home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / vs / rsmac.c next >
Encoding:
C/C++ Source or Header  |  1992-06-14  |  65.8 KB  |  2,455 lines

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4.  
  5. /*
  6.  *
  7.  *      Virtual Screen Kernel Macintosh Real Screen Interface
  8.  *                          (rsmac.c)
  9.  *
  10.  *   National Center for Supercomputing Applications
  11.  *      by Gaige B. Paulsen
  12.  *
  13.  *    This file contains the macintosh real screen calls for the NCSA
  14.  *  Virtual Screen Kernel.
  15.  *
  16.  *      RSbell(w)                   - Ring window w's bell
  17.  *      RScursoff(w)                - Turn the cursor off in w
  18.  *      RScurson(w,x,y)             - Turn the cursor on in w at x,y
  19.  *      RSdraw(w,x,y,a,len,ptr)     - Draw @x,y in w string@ptr for length len
  20.  *      RSdelchars(w,x,y,n)         - Delete n chars in w from x,y
  21.  *      RSdellines(w,t,b,n)         - Delete n lines in region t->b in w
  22.  *      RSerase(w,x1,y1,x2,y2)      - Erase from x1,y1 to x2,y2 in w
  23.  *      RSinitall()                 - Initialize the world if necessary
  24.  *      RSinslines(w,t,b,n)         - Insert n lines in region t->b in w
  25.  *      RSinsstring(w,x,y,a,len,ptr)- Insert len chars @x,y in w attrib a
  26.  *      RSsendstring(w,ptr,len)     - Send string @ptr length len from window w
  27.  *        RSbufinfo( w, total,current)- Tells you the total/current lines in buffer
  28.  *        RSdrawsep( w, y1,draw)        - Tells you to draw the line at y1 (0 is erase)
  29.  *        RSmargininfo( w, total, current)    - Tells you total/current columns in VS
  30.  *
  31.  *
  32.  *  Macintosh only Routines:
  33.  *    NI    RSregnconv( *)                - Convert region to rect coords
  34.  *  NI  RSsetwind(w)                - Set the port and vars to window w
  35.  *  NI  RSsetattr(a)                - Set font/text style to a
  36.  *    NI    RSsetConst(w)
  37.  *    ML    RSattach(w,wind)            - Attach the RS (w) to window wind
  38.  *    ML    RSdetach(w)                - Ready window for go-away
  39.  *    ML    RSselect(w,pt,shift)        - Handle selection RS (w) point (pt) and (shift) if held down
  40.  *    ML    RSzoom(window,code,shifted)    - Zoom Box handling
  41.  *    ML    RSsize( window, where)        - Resize handling
  42.  *    IN    RSgetwindow(w)                - Get the WindowPtr for RS (w)
  43.  *    IN    RSfindvwind(wind)            - Find the (RS/VS) # of wind
  44.  *    IN    RSfindscroll( control, n)    - Find which VS the control is in and which control it is
  45.  *      RSupdate(wind)                - Handle updates on WIND, return 0 if not an RS
  46.  *        RSactivate(w)                - Handle activate events 
  47.  *        RSdeactivate(w)                - Handle deactivate events 
  48.  *        RSGetTextSel(w,table)        - Returns handle to text selection of window w, table->tabs
  49.  *        RSchangefont(w,fnum,fsiz,r)    - Set (w) to font fnum, size fsiz, resize window if (r)
  50.  *        RSgetfont(w, &fnum, &fsiz)    - Get the font size and number into fnum and fsiz
  51.  *        RSnewwindow( wDims, sb, wid, lines
  52.  *            name,wrap,fnum,fsiz,
  53.  *            showit, goaway)            - Returns VS # of newly created text window -
  54.  *                                      wDims (dimension),sb(scrollback),wid(width 80/132),
  55.  *                                    lines (# of lines, 24 <> 66),
  56.  *                                      name(window), wrap(0/1),fnum,fsiz, showit(vis),goaway(0,1)
  57.  *        RSkillwindow( w)            - Destroys, deallocates, kills window (w)
  58.  *        RSclick(window,where,shift,
  59.  *                option)                - Handle clicks in window (returns false if not RS window)
  60.  *        RShide(w)                    - Hide RS (w)
  61.  *        RSshow(w)                    - Show RS (w)
  62.  *        RScprompt(w, FilterProc)    - Prompt for colors...FilterProc is for Modal Dialog
  63.  *        RSsetcolor(w,n,r,g,b)        - Set one of the 4 colors of RS (w) to R,G,B
  64.  *        RSgetcolor(w,n,r,g,b)        - Get one of the 4 colors of RS (w) into R,G,B
  65.  *        RSmouseintext(w,myPoint)    - Returns true if Mouse is in text part of current RS window
  66.  *        RSskip(w,on)                - Activate/deactivate drawing in an RS
  67.  *        
  68.  *        IN - Informational
  69.  *        ML - Mid Level
  70.  *        NI - Necessary Internal
  71.  *           - Suggested calls
  72.  *
  73.  *      Version Date    Notes
  74.  *      ------- ------  ---------------------------------------------------
  75.  *      0.01    861102  Initial coding -GBP
  76.  *      0.25    861106  Added code from screen.c -GBP
  77.  *      0.50    861113  First compiled edition -GBP
  78.  *        2.1        871130    NCSA Telnet 2.1 -GBP
  79.  *        2.2     880715    NCSA Telnet 2.2 -GBP
  80.  */
  81.  
  82.  
  83. #define __ALLNU__
  84. #include <Events.h>
  85. #include <Controls.h>
  86. #include <OSUtils.h>
  87. #include <Dialogs.h>
  88. #include <Quickdraw.h>
  89. #include <Palette.h>
  90. #include <Windows.h>
  91. #include <Menus.h>
  92. #include <Fonts.h>
  93. #include <Memory.h>
  94. #include <stdio.h>
  95. #include <string.h>
  96.  
  97. typedef
  98.     Rect *RectPtr;
  99.  
  100. #include "whatami.h"
  101. #include "configrec.h"
  102. #include "maclook.h"
  103. #include "user.h"
  104. #include "vskeys.h"
  105. #include "vsdata.h"
  106. #include "vsinterf.h"
  107.  
  108. #ifdef MPW
  109. #include "mpw.h"
  110. #include <Picker.h>
  111. #endif
  112.  
  113. #define NCSA_TELNET
  114.  
  115. #ifdef NCSA_TELNET
  116. #include "wind.h"
  117. #endif
  118.  
  119. /*
  120. *  Capable of shifting the text to the right some # of pixels
  121. */
  122. #define CVO 0
  123. #define CHO -3
  124.  
  125. #define Fheight RSlocal[w].fheight
  126. #define    Fascent    RSlocal[w].fascent
  127. #define Fwidth RSlocal[w].fwidth
  128. #define    FONT RSlocal[w].fnum
  129. #define FSIZE RSlocal[w].fsiz
  130. #define Fright RSlocal[w].width
  131. #define MAXWINDOWWIDTH (width)*Fwidth+16-CHO
  132. #define MAXWINDOWHEIGHT (lines)*Fheight+16
  133.  
  134. #define BLOCKCURSOR                0    /* BYU 2.4.11 */
  135. #define UNDERSCORECURSOR        1    /* BYU 2.4.11 */
  136. #define VERTICALCURSOR            2    /* BYU 2.4.11 */
  137.  
  138. #define Edit        2        /*  Edit Menu's Position */
  139. #define EDcopy        4        /* Edit Menu: Copy */
  140. #define EDcopyt        7        /* Edit Menu: Copy Table */
  141.  
  142. #define    Fil            1        /*    File Menu's Position */
  143. #define FLprint        12        /* File Menu: Print Selection */
  144. extern MenuHandle myMenus[];
  145.  
  146.  
  147. #define putln(x)
  148.  
  149. extern unsigned char tempspot[];
  150.  
  151. extern short        /* BYU 2.4.11 - From event.c */
  152.     cursorBlink,    /* BYU 2.4.11 - 0 = noblink, 1 = blink */
  153.     cursorType;        /* BYU 2.4.11 - 0 = block, 1 = underscore, 2 = vertical line */
  154. extern int HasColor;            /* BYU */
  155. extern int VSIcursorvisible();    /* BYU 2.4.12 */
  156. extern int VSvalids();            /* BYU 2.4.12 */
  157.  
  158. struct RSdata {
  159.     Rect        textrect;    /* Where the text is in the window */
  160.     Rect        cursor;        /* Cursor rectangle */
  161.     GrafPtr        window;        /* Window pointer */
  162.     PaletteHandle    pal;    /* My Palette */
  163.     char        cursorstate,/* BYU 2.4.11 - 0 is invisible, 1 is visible */
  164.                 selected;    /* BYU 2.4.11 - text is selected */
  165.     long        last,
  166.                 anchor;
  167.     int            topline,
  168.                 leftmarg;    /* leftmost visible column position */
  169.     int            rheight,    /* Real window dimensions */
  170.                             /* adjusted to not include CHO boundary - TK 12/88 */
  171.                 rwidth;
  172.     int            height,
  173.                 width;        /* Window Dimensions rounded to the nearest character */
  174.     char        color[6];    /* color scheme for this machine's sessions */
  175.     RGBColor    RGBs[4];    /* RGB Colors for window */
  176.     ControlHandle
  177.         left,        /* The CH for the left margin */
  178.         scroll;        /* The CH for the scroll bar */
  179.     int
  180.         min,        /* Minimum vertical scrollbar value (number of lines in screen buffer and scrollback) */
  181.         max,        /* Maximum vertical scrollbar value */
  182.         current,    /* current vertical scrollbar value */
  183.         lmin,        /* Minimum horizontal scrollbar value (always 0) */
  184.         lmax,        /* Maximum horizontal scrollbar value (number of columns not visible) */
  185.         lcurrent;    /* current horizontal scrollbar value (leftmost visible column) */
  186.     int
  187.         fascent,    /* Font Ascent */
  188.         fnum,        /* Font ID */
  189.         fsiz,        /* Font Size */
  190.         fheight,    /* Font Height/character */
  191.         fwidth,        /* Font Width /character */
  192.         monospaced;    /* Font is monospaced */
  193.     int
  194.         skip;        /* TRUE if we are skipping the output */
  195.  
  196.     };
  197.  
  198. typedef struct RSdata RSdata;
  199.  
  200. extern int scrn,numwindows;
  201. #ifdef NCSA_TELNET
  202. extern WindRec *screens;
  203. #endif NCSA_TELNET
  204. pascal void ScrollProc();
  205.  
  206. CTabHandle RSctab;
  207. int MaxRS;
  208. long blinktime;                    /* BYU 2.4.11 */
  209. RSdata *RSlocal, *RScurrent;
  210. Rect    noConst,
  211.         screenRect,
  212.         RScur;                /* cursor rectangle */
  213. RgnHandle RSuRgn;            /* update region */
  214. int RSw=-1,         /* last window used */
  215.     RSa=0;          /* last attrib used */
  216. int RScolor=1;        /* true if try to use color stuff */
  217. int RScolors[]=
  218.     { 33,            /* black */
  219.       30,            /* white */
  220.       205,            /* red */
  221.       341,            /* green */
  222.       409,            /* blue */
  223.       273,            /* cyan */
  224.       137,            /* magenta */
  225.       69            /* yellow */
  226.       };
  227.  
  228. void RSinitall
  229.   (
  230.     int max /* max nr windows to allow */
  231.   )
  232.   /* initializes handling of terminal windows. */
  233.   {
  234.     int i;
  235.     extern SysEnvRec theWorld;
  236.  
  237.     MaxRS = max;
  238.     RSlocal = (RSdata *) NewPtr(MaxRS * sizeof(RSdata));
  239.     for (i = 0; i < MaxRS; RSlocal[i++].window = 0L)
  240.       {
  241.         RScurrent = RSlocal + i;
  242.         RScurrent->color[0] = 0;            /* Foreground */
  243.         RScurrent->color[1] = 1;            /* Background */
  244.         RScurrent->color[2] = 2;            /* Blink Fore */
  245.         RScurrent->color[3] = 3;            /* Blink Back */
  246.         RScurrent->cursor.top = 0;
  247.         RScurrent->cursor.bottom = 0;
  248.         RScurrent->cursor.left = 0;
  249.         RScurrent->cursor.right = 0;
  250.       }
  251.     RSuRgn = NewRgn();
  252.     RScur.left = 0;
  253.     RScur.top = 0;
  254.     RScur.bottom = 0;
  255.     RScur.right = 0;
  256.     RSctab = (CTabHandle) NewHandle((long) (sizeof(ColorTable) + 8 * sizeof(CSpecArray)));
  257.     RScolor = theWorld.hasColorQD;
  258.   } /* RSinitall */
  259.  
  260. int RSTextSelected(int w) {        /* BYU 2.4.11 */
  261.   return(RSlocal[w].selected);    /* BYU 2.4.11 */
  262. }                                /* BYU 2.4.11 */
  263.  
  264. void RSsetConst
  265.   (
  266.     int w
  267.   )
  268.   /* sets "noConst" global to a zero-based rectangle equal in size
  269.     to the specified terminal window. */
  270.   {
  271.     SetRect(&noConst, 0, 0, RSlocal[w].width, RSlocal[w].height);
  272.   } /* RSsetConst */
  273.  
  274. /****************************************************************************/
  275. /*  Given a window record number, do a SetPort() to the window associated with
  276. *   that window record.
  277. */
  278. int RSsetwind
  279.   (
  280.     int w
  281.   )
  282.   {
  283.     if ((w < 0) || (w > MaxRS))
  284.         return(-3);
  285.     if (RSw != w)                                /* if last window used is different */
  286.       {
  287.         if (RSlocal[w].window == 0L)
  288.             return(-4);
  289.         RScurrent = RSlocal + w;
  290.         RSw = w;
  291.         RSa = -1; /* attributes will need setting */
  292.         SetPort(RScurrent->window);
  293.         return(1);
  294.       }
  295.     SetPort(RScurrent->window);
  296.     return(0);
  297.   } /* RSsetwind */
  298.  
  299. void RSbell
  300.   (
  301.     int w
  302.   )
  303.   /* gives an audible signal associated with the specified window. */
  304.   {
  305.     RSsetwind(w);
  306.     if (FrontWindow() != RScurrent->window)
  307.       {
  308.       /* beep and temporarily invert the window contents, so
  309.         the user sees which window is beeping */
  310.         InvertRect(&RScurrent->window->portRect);
  311.         SysBeep(8);
  312.         InvertRect(&RScurrent->window->portRect);
  313.       }
  314.     else
  315.       /* window is frontmost--just beep */
  316.         SysBeep(8);
  317.   } /* RSbell */
  318.  
  319. void RScursblink                        /* BYU 2.4.11 */
  320.   (                                        /* BYU 2.4.11 */
  321.     int w                                /* BYU 2.4.11 */
  322.   )                                        /* BYU 2.4.11 */
  323.   /* Blinks the cursor */                /* BYU 2.4.11 */
  324.   {                                        /* BYU 2.4.11 */
  325.     GrafPtr oldwindow;                    /* BYU 2.4.11 */
  326.     long now = TickCount();                /* BYU 2.4.11 */
  327.     if (now > blinktime) {                /* BYU 2.4.11 */
  328.         if (VSvalids(w) != 0)            /* BYU 2.4.12 */
  329.             return;                        /* BYU 2.4.12 */
  330.         if (!VSIcursorvisible())        /* BYU 2.4.12 */
  331.             return;                        /* BYU 2.4.12 - cursor isn't visible */
  332.         GetPort(&oldwindow);            /* BYU 2.4.11 */
  333.         blinktime = now + 40;            /* BYU 2.4.11 */
  334.         RSlocal[w].cursorstate ^= 1;     /* BYU 2.4.11 */
  335.         SetPort(RSlocal[w].window);        /* BYU 2.4.11 */
  336.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.11 */
  337.         SetPort(oldwindow);                /* BYU 2.4.11 */
  338.     }                                    /* BYU 2.4.11 */
  339.   } /* RScursblink */                    /* BYU 2.4.11 */
  340.  
  341. void RScursblinkon                        /* BYU 2.4.18 */
  342.   (                                        /* BYU 2.4.18 */
  343.     int w                                /* BYU 2.4.18 */
  344.   )                                        /* BYU 2.4.18 */
  345.   /* Blinks the cursor */                /* BYU 2.4.18 */
  346.   {                                        /* BYU 2.4.18 */
  347.       if (!RSlocal[w].cursorstate) {        /* BYU 2.4.18 */
  348.         GrafPtr oldwindow;                /* BYU 2.4.18 */
  349.         GetPort(&oldwindow);            /* BYU 2.4.18 */
  350.         RSlocal[w].cursorstate = 1;     /* BYU 2.4.18 */
  351.         SetPort(RSlocal[w].window);        /* BYU 2.4.18 */
  352.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.18 */
  353.         SetPort(oldwindow);                /* BYU 2.4.18 */
  354.     }                                    /* BYU 2.4.18 */
  355.   } /* RScursblink */                    /* BYU 2.4.18 */
  356.  
  357. void RScursblinkoff                        /* BYU 2.4.11 */
  358.   (                                        /* BYU 2.4.11 */
  359.     int w                                /* BYU 2.4.11 */
  360.   )                                        /* BYU 2.4.11 */
  361.   /* Blinks the cursor */                /* BYU 2.4.11 */
  362.   {                                        /* BYU 2.4.11 */
  363.       if (RSlocal[w].cursorstate) {        /* BYU 2.4.11 */
  364.         GrafPtr oldwindow;                /* BYU 2.4.11 */
  365.         GetPort(&oldwindow);            /* BYU 2.4.11 */
  366.         RSlocal[w].cursorstate = 0;     /* BYU 2.4.11 */
  367.         SetPort(RSlocal[w].window);        /* BYU 2.4.11 */
  368.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.11 */
  369.         SetPort(oldwindow);                /* BYU 2.4.11 */
  370.     }                                    /* BYU 2.4.11 */
  371.   } /* RScursblink */                    /* BYU 2.4.11 */
  372.  
  373. void RScursoff
  374.   (
  375.     int w
  376.   )
  377.   /* hides the text cursor for the specified window. Assumes it
  378.     is currently being shown. */
  379.   {
  380.     if (RSlocal[w].skip || !RSlocal[w].cursorstate)        /* BYU 2.4.11 */
  381.         return;
  382.     RSsetwind(w);
  383.     RScurrent->cursorstate = 0;                            /* BYU 2.4.11 */
  384.     InvertRect(&RScurrent->cursor);
  385.   } /* RScursoff */
  386.  
  387. void RScurson
  388.   (
  389.     int w,
  390.     int x,
  391.     int y
  392.   )
  393.   /* displays the text cursor for the specified window, at the
  394.     specified position. Assumes it isn't currently being shown. */
  395.   {
  396.     if (RSlocal[w].skip || RSlocal[w].cursorstate)        /* BYU 2.4.11 */
  397.         return;
  398.     RSsetwind(w);
  399.  
  400.     RScurrent->cursor.left = x * RScurrent->fwidth;            /* BYU 2.4.11 */
  401.     RScurrent->cursor.top  = y * RScurrent->fheight;        /* BYU 2.4.11 */
  402.  
  403.     switch (cursorType) {                                            /* BYU 2.4.11 */
  404.         case UNDERSCORECURSOR:                                        /* BYU 2.4.11 */
  405.             RScurrent->cursor.top  += RScurrent->fheight;            /* BYU 2.4.11 */
  406.             RScurrent->cursor.right  = RScurrent->cursor.left + RScurrent->fwidth;    /* BYU 2.4.11 */
  407.             RScurrent->cursor.bottom = RScurrent->cursor.top + 1;    /* BYU 2.4.11 */
  408.             break;
  409.         case VERTICALCURSOR:                                        /* BYU 2.4.11 */
  410.             RScurrent->cursor.left += 2;                            /* BYU 2.4.11 */
  411.             RScurrent->cursor.right  = RScurrent->cursor.left + 1;    /* BYU 2.4.11 */
  412.             RScurrent->cursor.bottom = RScurrent->cursor.top + RScurrent->fheight;    /* BYU 2.4.11 */
  413.             break;
  414.         case BLOCKCURSOR:                                            /* BYU 2.4.11 */
  415.         default:                                                    /* BYU 2.4.11 */
  416.             RScurrent->cursor.right  = RScurrent->cursor.left + RScurrent->fwidth;    /* BYU 2.4.11 */
  417.             RScurrent->cursor.bottom = RScurrent->cursor.top + RScurrent->fheight;    /* BYU 2.4.11 */
  418.             break;
  419.     }
  420.  
  421.     if (!cursorBlink) {                                    /* BYU 2.4.11 */
  422.         RScurrent->cursorstate = 1;                        /* BYU 2.4.11 */
  423.         InvertRect(&RScurrent->cursor);                    /* BYU 2.4.11 */
  424.     }                                                    /* BYU 2.4.11 */
  425.   } /* RScurson */
  426.  
  427. void RSTextFont(myfnum,myfsiz,myface)     /* BYU */
  428. int myfnum,myfsiz,myface;                 /* BYU */
  429. {                                        /* BYU */
  430.     if ((myfnum == monaco) &&             /* BYU - If Monaco, size 9, and bold, then */
  431.         (myfsiz == 9) &&                /* BYU */
  432.         (myface & bold))    {            /* BYU */
  433.         TextFont(75);                    /* BYU - use NCSA's Monaco. */
  434.     } else {                            /* BYU */
  435.         TextFont(myfnum);                /* BYU */
  436.     }                                    /* BYU */
  437. }                                        /* BYU */
  438.  
  439. void RSsetattr
  440.   (
  441.     int a
  442.   )
  443.   /* sets the text attributes for drawing into the current window. */
  444.   {
  445.     if (VSisgrph(a))
  446.         TextFont(74); /* use "NCSA VT" font for special graphics */
  447.     else
  448. #if 1                                                    /* BYU */
  449.         RSTextFont(RScurrent->fnum,RScurrent->fsiz,a);     /* BYU - use user-selected text font */
  450. #else
  451.         TextFont(RScurrent->fnum); /* use user-selected text font */
  452. #endif
  453.     TextSize(RScurrent->fsiz);
  454.  
  455. /* Jim@BYU - bold system fonts don't work (they overwrite the scroll bars), 
  456.          but NCSA's 9 point Monaco bold works okay. */
  457.  
  458.     TextFace((a & outline) >> 1);     /* Jim@BYU - do outline as underline setting */
  459.  
  460.  
  461. #if 0                                    /* BYU - experimental */
  462. #if 1                                    /* BYU */
  463.     if ((RScurrent->fnum == monaco) &&     /* BYU */
  464.         (RScurrent->fsiz == 9))            /* BYU */
  465.         TextFace((a & outline) >> 1);     /* BYU - do outline as underline setting */
  466.     else                                /* BYU */
  467.         TextFace((a & outline) >> 1);    /* BYU - bold + outline as underline settings */
  468. #else
  469.     TextFace((a & bold) + (a & outline) /2); /* BYU - bold + outline as underline settings */
  470. #endif
  471. #endif
  472.  
  473.  
  474.  
  475.   /* set up reverse video setting */
  476.     if (RScolor)
  477.       {
  478.         if (VSisrev(a))
  479.             TextMode(notSrcCopy);
  480.         else
  481.             TextMode(srcCopy);
  482.       }
  483.     else
  484.       {
  485.         if (VSisrev(a))
  486.           {
  487.             BackPat(qd.black);    /* Reverses current attributes regard */
  488.             PenPat(qd.white);    /* less of the color, etc.... */
  489.           }
  490.         else
  491.           {
  492.             BackPat(qd.white);
  493.             PenPat(qd.black);
  494.           } /* if */
  495.       } /* if */
  496.   /* use colors to stand in for blink setting */
  497.     if (VSisblnk(a))
  498.       {
  499.         if (RScolor)
  500.           {
  501.             PmForeColor(2);
  502.             PmBackColor(3);
  503.           }
  504.         else
  505.           {
  506.             ForeColor((long) RScolors[RScurrent->color[2]]);    /* Blink foreground */
  507.             BackColor((long) RScolors[RScurrent->color[3]]);    /* Blink Background */
  508.           } /* if */
  509.       }
  510.     else
  511.       {
  512.         if (RScolor)
  513.           {
  514.             PmForeColor(0);
  515.             PmBackColor(1);
  516.           }
  517.         else
  518.           {
  519.             ForeColor((long) RScolors[RScurrent->color[0]]);    /* normal foreground */
  520.             BackColor((long) RScolors[RScurrent->color[1]]);    /* normal Background */
  521.           } /* if */
  522.       } /* if */
  523.     RSa = a;
  524.   } /* RSsetattr */
  525.  
  526. void HiliteMode(void)
  527.   /* enables use of highlighting in place of simple color inversion
  528.     for next QuickDraw operation. */
  529.   {
  530.     char *p = (char *) 0x938; /* pointer to HiliteMode low-memory global */
  531.     *p = *p & 0x7f; /* clear the HiliteBit */
  532.   } /* HiliteMode */
  533.  
  534. void RSinvText
  535.   (
  536.     int w, 
  537.     Point curr,
  538.     Point last,
  539.     RectPtr constrain /* don't highlight anything outside this rectangle */
  540.   )
  541.   /* highlights the text from curr to last inclusive. */
  542.   {
  543.     Rect temp, temp2;
  544.     Point lb, ub;
  545.  
  546.     RSsetwind(w);
  547.   /* normalize coordinates with respect to visible area of virtual screen */
  548.     curr.v -= RScurrent->topline;
  549.     curr.h -= RScurrent->leftmarg;
  550.     last.v -= RScurrent->topline;
  551.     last.h -= RScurrent->leftmarg;
  552.  
  553.     if (curr.v == last.v)
  554.       {
  555.       /* highlighted text all on one line */
  556.         if (curr.h < last.h) /* get bounds the right way round */
  557.           {
  558.             ub = curr;
  559.             lb = last;
  560.           }
  561.         else
  562.           {
  563.             ub = last;
  564.             lb = curr;
  565.           } /* if */
  566.         SetRect /* set up rectangle bounding area to be highlighted */
  567.           (
  568.             &temp,
  569.             (ub.h + 1) * RScurrent->fwidth,
  570.             ub.v * RScurrent->fheight,
  571.             (lb.h + 1) * RScurrent->fwidth,
  572.             (lb.v + 1) * RScurrent->fheight
  573.           );
  574.         SectRect(&temp, constrain, &temp2); /* clip to constraint rectangle */
  575.         HiliteMode();
  576.         InvertRect(&temp2);
  577.       }
  578.     else
  579.       {
  580.       /* highlighting across more than one line */
  581.         if (curr.v < last.v)
  582.             ub = curr;
  583.         else
  584.             ub = last;
  585.         if (curr.v > last.v)
  586.             lb = curr;
  587.         else
  588.             lb = last;
  589.         SetRect /* bounds of first (possibly partial) line to be highlighted */
  590.           (
  591.             &temp,
  592.             (ub.h + 1) * RScurrent->fwidth,
  593.             ub.v * RScurrent->fheight,
  594.             RScurrent->width,
  595.             (ub.v + 1) * RScurrent->fheight
  596.           );
  597.         SectRect(&temp, constrain, &temp2); /* clip to constraint rectangle */
  598.         HiliteMode();
  599.         InvertRect(&temp2);
  600.         SetRect /* bounds of last (possibly partial) line to be highlighted */
  601.           (
  602.             &temp,
  603.             0,
  604.             lb.v * RScurrent->fheight,
  605.             (lb.h + 1) * RScurrent->fwidth,
  606.             (lb.v + 1) * RScurrent->fheight
  607.           );
  608.         SectRect(&temp, constrain, &temp2); /* clip to constraint rectangle */
  609.         HiliteMode();
  610.         InvertRect(&temp2);
  611.         if (lb.v - ub.v > 1) /* highlight extends across more than two lines */
  612.           {
  613.           /* highlight complete in-between lines */
  614.             SetRect
  615.               (
  616.                 &temp,
  617.                 0,
  618.                 (ub.v + 1) * RScurrent->fheight,
  619.                 RScurrent->width,
  620.                 lb.v * RScurrent->fheight
  621.               );
  622.             SectRect(&temp, constrain, &temp2); /* clip to constraint rectangle */
  623.             HiliteMode();
  624.             InvertRect(&temp2);
  625.           } /* if */
  626.       } /* if */
  627.   } /* RSinvText */
  628.  
  629. void RSdraw
  630.   (
  631.     int w, /* window number */
  632.     int x, /* starting column */
  633.     int y, /* line on which to draw */
  634.     int a, /* text attributes */
  635.     int len, /* length of text to draw */
  636.     char *ptr /* pointer to text */
  637.   )
  638.   /* draws a piece of text (assumed to fit on a single line) in a window,
  639.     using the specified attributes. If any part of the text falls
  640.     within the current selection, it will be highlighted. */
  641.   {
  642.     Rect rect;
  643.     static char temp[128];
  644.     int ys;
  645.     static int theLen;
  646.  
  647.     if (RSlocal[w].skip)
  648.         return;
  649.     RSsetwind(w);
  650.     RSsetattr(0);
  651.     SetRect /* set up rectangle bounding text being drawn */
  652.       (
  653.         &rect,
  654.         x * RScurrent->fwidth,
  655.         y * RScurrent->fheight,
  656.         (x + len) * RScurrent->fwidth,
  657.         (y + 1) * RScurrent->fheight
  658.       );
  659.     if (RSa != a)
  660.         RSsetattr(a);
  661.     if (x <= 0)            /* BYU 2.4.12 - Without this, 1 pixel column of reverse */
  662.       rect.left = -3;    /* BYU 2.4.12 - video text does not clear at left margin */
  663. #ifdef OLDM
  664.     if (!RScolor)
  665. #endif OLDM
  666.         EraseRect(&rect);
  667.     if (x <= 0)            /* BYU 2.4.12 - Okay, just putting it back the way it was */
  668.       rect.left = 0;    /* BYU 2.4.12 */
  669.     ys = y * RScurrent->fheight + RScurrent->fascent;
  670.         MoveTo(x * RScurrent->fwidth, ys);
  671.     strncpy(temp,ptr,len);
  672.     temp[len]=0;
  673.     theLen = StringWidth(temp);
  674.     
  675. #ifdef NEWTXT
  676.         DrawText(ptr, 0, len);
  677.         
  678. #else
  679.     if (RScurrent->monospaced)
  680.         DrawText(ptr, 0, len);
  681.     else
  682.         while (len--)
  683.           {
  684.           /* draw the characters one at a time to defeat the proportional spacing */
  685.             DrawChar(*ptr++);
  686.             MoveTo((++x) * RScurrent->fwidth, ys);  /*good version */
  687. /*            MoveTo((++x) * CharWidth(*(ptr-1)), ys); */
  688.           } /* while */
  689. #endif
  690.     if (RScurrent->selected)
  691.         RSinvText(w, *(Point *) &RScurrent->anchor,
  692.             *(Point *) &RScurrent->last, &rect);
  693.   } /* RSdraw */
  694.  
  695. void RSdelcols
  696.   (
  697.     int w,
  698.     int n /* number of columns to scroll */
  699.   )
  700.   /* scrolls the entire visible display of a virtual screen the
  701.     specified number of columns to the left, blanking out
  702.     the newly-revealed area. */
  703.   {
  704.     Rect rect;
  705.  
  706.     if (RSlocal[w].skip)
  707.         return;
  708.     RSsetwind(w);
  709.     SetRect /* bounds of entire text area, for scrolling */
  710.       (
  711.         &rect,
  712.         0,
  713.         0,
  714.         RScurrent->width,
  715.         RScurrent->height
  716.       );
  717.     ScrollRect(&rect, -n * RScurrent->fwidth, 0, RSuRgn);
  718.     InvalRgn(RSuRgn);
  719.     ValidRect(&rect); /* any necessary redrawing in newly-revealed area will be done by caller */
  720.     SetRect /* bounds of newly-revealed area */
  721.       (
  722.         &rect,
  723.         RScurrent->width - (n * RScurrent->fwidth),
  724.         0,
  725.         RScurrent->width,
  726.         RScurrent->height
  727.       );
  728.     if (RScurrent->selected)
  729.       /* highlight any newly-revealed part of the current selection */
  730.         RSinvText(w, *(Point *) &RScurrent->anchor,
  731.             *(Point *) &RScurrent->last, &rect);
  732.   } /* RSdelcols */
  733.  
  734. void RSdelchars
  735.   (
  736.     int w, /* affected window */
  737.     int x, /* column to delete from */
  738.     int y, /* line on which to do deletion */
  739.     int n /* number of characters to delete */
  740.   )
  741.   /* deletes the specified number of characters from the specified
  742.     position to the right, moving the remainder of the line to the
  743.     left. */
  744.   {
  745.     Rect rect;
  746.  
  747.     if (RSlocal[w].skip)
  748.         return;
  749.     RSsetwind(w);
  750.     RSsetattr(0); /* avoid funny pen modes */
  751.     SetRect /* bounds of area from starting column to end of line */
  752.       (
  753.         &rect,
  754.         x * RScurrent->fwidth,
  755.         y * RScurrent->fheight,
  756.         RScurrent->width,
  757.         (y + 1) * RScurrent->fheight
  758.       );
  759.     if ((x + n) * RScurrent->fwidth > RScurrent->width)
  760.       /* deleting to end of line */
  761.         EraseRect(&rect);
  762.     else
  763.       {
  764.       /* scroll remainder of line to the left */
  765.         ScrollRect(&rect, - RScurrent->fwidth * n, 0, RSuRgn);
  766.         InvalRgn(RSuRgn);
  767.            ValidRect(&rect); /* leave newly-revealed area blank */
  768.         if (RScurrent->selected)
  769.           {
  770.           /* highlight any part of selection which lies in newly-blanked area */
  771.             HLock((Handle) RSuRgn);
  772.             RSinvText(w, *(Point *) &RScurrent->anchor, *(Point *) &RScurrent->last, &((*RSuRgn)->rgnBBox));
  773.             HUnlock((Handle) RSuRgn);
  774.           } /* if */
  775.       } /* if */
  776.   } /* RSdelchars */
  777.  
  778. void RSdellines
  779.   (
  780.     int w, /* affected window */
  781.     int t, /* top line of affected region */
  782.     int b, /* bottom line of affected region */
  783.     int n, /* number of lines to delete */
  784.     int scrolled
  785.       /*
  786.         -ve => cancel current selection, if any;
  787.         +ve => selection has moved up one line;
  788.         0 => don't touch selection
  789.       */
  790.   )
  791.   /* deletes lines at the top of the specified region of a window,
  792.     inserting new blank lines at the bottom, and scrolling up the
  793.     stuff in between. */
  794.   {
  795.     Rect rect;
  796.  
  797.     if (RSlocal[w].skip)
  798.         return;
  799.     RSsetwind(w);
  800.     RSsetConst(w);
  801.     RSsetattr(0); /* avoid funny pen modes */
  802.     if (scrolled)
  803.       {
  804.         if (RScurrent->selected && scrolled < 0)
  805.           {
  806.           /* unhighlight and cancel current selection */
  807.             RSinvText(w, *(Point *) &RScurrent->anchor, *(Point *) &RScurrent->last, &noConst);
  808.             RScurrent->selected = 0;
  809.           }
  810.         else
  811.           {
  812.             RScurrent->last -= 65536;        /* Subtract one from each of the */
  813.             RScurrent->anchor -= 65536;        /* Selection components */
  814.           } /* if */
  815.       } /* if */
  816.  
  817.     rect.left = -1;                            /* BYU 2.4.12 - necessary */
  818.     rect.right = RScurrent->width;
  819.     rect.top = t * RScurrent->fheight;
  820.     rect.bottom = (b + 1) * RScurrent->fheight;
  821.   /* adjust the update region to track the scrolled window contents */
  822.     OffsetRgn(((WindowPeek) RScurrent->window)->updateRgn,
  823.         0, - RScurrent->fheight * n);
  824.     ScrollRect(&rect, 0, - RScurrent->fheight * n, RSuRgn);
  825.     RSsetattr(VSIw->attrib); /* restore mode for text drawing */
  826.     InvalRgn(RSuRgn);
  827.   /* validate the area containing the newly-inserted blank lines. */
  828.   /* any necessary redrawing in newly-revealed area will be done by caller */
  829.     SetRect
  830.       (
  831.         &rect,
  832.         0,
  833.         (b - n + 1) * RScurrent->fheight - 1,
  834.         Fright,
  835.         (b + 1) * RScurrent->fheight + 1
  836.       );
  837.     ValidRect(&rect);
  838.   } /* RSdellines */
  839.  
  840. void RSerase
  841.   (
  842.     int w, /* affected window */
  843.     int x1, /* left column */
  844.     int y1, /* top line */
  845.     int x2, /* right column */
  846.     int y2 /* bottom line */
  847.   )
  848.   /* erases a rectangular portion of the screen display, preserving
  849.     the selection highlight. */
  850.   {
  851.     Rect rect;
  852.  
  853.     if (RSlocal[w].skip)
  854.         return;
  855.     RSsetwind(w);
  856.     RSsetattr(0); /* avoid funny pen modes */
  857.     SetRect
  858.       (
  859.         &rect,
  860.         x1 * RScurrent->fwidth,
  861.         y1 * RScurrent->fheight,
  862.         (x2 + 1) * RScurrent->fwidth - 1,
  863.         (y2 + 1) * RScurrent->fheight + 1
  864.       );
  865.     if (rect.left <= 0)                        /* little buffer strip on left */
  866.         rect.left = CHO;
  867.     if (rect.right >= RScurrent->width - 1)
  868.         rect.right = RScurrent->rwidth - 2;    /* clear to edge of window, including edge strip */
  869.     if (rect.bottom >= RScurrent->height - 2)
  870.         rect.bottom = RScurrent->rheight + 1;    /* clear to bottom edge also */
  871.     EraseRect(&rect);
  872.     if (RScurrent->selected)
  873.       /* highlight any part of the selection within the cleared area */
  874.         RSinvText(w, *(Point *) &RScurrent->anchor, *(Point *) &RScurrent->last, &rect);
  875.   } /* RSerase */
  876.  
  877. void RSinslines
  878.   (
  879.     int w, /* affected window */
  880.     int t, /* where to insert blank lines */
  881.     int b, /* bottom of area to scroll */
  882.     int n, /* number of lines to insert */
  883.     int scrolled /* -ve <=> cancel current selection, if any */
  884.   )
  885.   /* inserts blank lines at the top of the given area of the display,
  886.     scrolling the rest of it down. */
  887.   {
  888.     Rect rect;
  889.  
  890.     if (RSlocal[w].skip)
  891.         return;
  892.     RSsetwind(w);
  893.     RSsetConst(w);
  894.     RSsetattr(0); /* avoid funny pen modes */
  895.     if (RScurrent->selected && (scrolled < 0))
  896.       {
  897.       /* unhighlight and cancel selection */
  898.         RSinvText(w, *(Point *) &RScurrent->anchor,
  899.             *(Point *) &RScurrent->last, &noConst);
  900.         RScurrent->selected = 0;
  901.       } /* if */
  902.     rect.left = -1;                        /* BYU 2.4.12 - necessary */
  903.     rect.right = RScurrent->width;
  904.     rect.top = t * RScurrent->fheight;
  905.     rect.bottom = (b + 1) * RScurrent->fheight;
  906.   /* adjust the update region to track the scrolled window contents */
  907.     OffsetRgn(((WindowPeek) RScurrent->window)->updateRgn,
  908.         0, RScurrent->fheight * n);
  909.     ScrollRect(&rect, 0, RScurrent->fheight * n, RSuRgn);
  910.     InvalRgn(RSuRgn);
  911.   /* newly-inserted area is already blank -- validate it to avoid redrawing. */
  912.   /* any necessary redrawing will be done by caller */
  913.     SetRect(&rect, 0, t * RScurrent->fheight - 1,
  914.         RScurrent->width, (t + n) * RScurrent->fheight + 1);
  915.     ValidRect(&rect);
  916.   } /* RSinslines */
  917.  
  918. void RSinscols
  919.   (
  920.     int w,
  921.     int n /* number of columns to insert */
  922.   )
  923.   /* inserts blank columns at the left side of the text display in
  924.     the specified window, scrolling its current contents to the right.
  925.     Maintains the selection highlight, but doesn't move the selection.
  926.     Doesn't even unhighlight text which moves out of the selection area. */
  927.   {
  928.     Rect rect;
  929.  
  930.     if (RSlocal[w].skip)
  931.         return;
  932.     RSsetwind(w);
  933.     SetRect /* bounds of entire text area */
  934.       (
  935.         &rect,
  936.         0,
  937.         0,
  938.         RScurrent->width,
  939.         RScurrent->height
  940.       );
  941.     ScrollRect(&rect, n * RScurrent->fwidth, 0, RSuRgn);
  942.     InvalRgn(RSuRgn);
  943.     ValidRect(&rect); /* any necessary redrawing in newly-revealed area will be done by caller */
  944.     SetRect /* bounds of newly-inserted blank area */
  945.       (
  946.         &rect,
  947.         0,
  948.         0,
  949.         (n + 1) * RScurrent->fwidth - 1,
  950.         RScurrent->height
  951.       );
  952.     if (RScurrent->selected)
  953.       /* highlight any part of the selection in the newly-blanked area */
  954.         RSinvText(w, *(Point *) &RScurrent->anchor, *(Point *) &RScurrent->last, &rect);
  955.   } /* RSinscols */
  956.  
  957. void RSinsstring
  958.   (
  959.     int w, /* affected window */
  960.     int x, /* starting column at which to insert */
  961.     int y, /* line on which to insert */
  962.     int a, /* attributes for inserted text */
  963.     int len, /* length of inserted text */
  964.     char *ptr /* pointer to inserted text */
  965.   )
  966.   /* inserts a string of characters at the specified position, scrolling
  967.     the rest of the line to the right. Highlights any part of the newly-
  968.     inserted text lying within the current selection. */
  969.   {
  970.     Rect rect;
  971.  
  972.     if (RSlocal[w].skip)
  973.         return;
  974.     RSsetwind(w);
  975.     SetRect /* bounds of part of line from specified position to end of line */
  976.       (
  977.         &rect,
  978.         x * RScurrent->fwidth,
  979.         y * RScurrent->fheight,
  980.         RScurrent->width,
  981.         (y + 1) * RScurrent->fheight
  982.       );
  983.     ScrollRect(&rect, len * RScurrent->fwidth, 0, RSuRgn); /* scroll remainder of line to the right */
  984.     if (RSa != a)
  985.         RSsetattr(a);
  986.     InvalRgn(RSuRgn);
  987.     ValidRect(&rect); /* any necessary redrawing in newly-revealed area will be done by caller */
  988.     SetRect /* bounds area to contain inserted string */
  989.       (
  990.         &rect,
  991.         x * RScurrent->fwidth,
  992.         y * RScurrent->fheight,
  993.         (x + len) * RScurrent->fwidth,
  994.         (y + 1) * RScurrent->fheight
  995.       );
  996.     EraseRect(&rect); /* erase area to appropriate background */
  997.     MoveTo
  998.       (
  999.         x * RScurrent->fwidth,
  1000.         y * RScurrent->fheight + RScurrent->fascent
  1001.       );
  1002.     DrawText(ptr, 0, len);
  1003.     if (RScurrent->selected)
  1004.       /* highlight any part of selection covering the newly-inserted text */
  1005.         RSinvText(w, *(Point *) &RScurrent->anchor,
  1006.             *(Point *) &RScurrent->last, &rect);
  1007.   } /* RSinsstring */
  1008.  
  1009. void RSsendstring
  1010.   (
  1011.     int w, /* which terminal window */
  1012.     char *ptr, /* pointer to data */
  1013.     int len /* length of data */
  1014.   )
  1015.   /* sends some data to the host along the connection associated
  1016.     with the specified window. */
  1017.   {
  1018. #ifdef NCSA_TELNET
  1019.     int temp;
  1020.  
  1021.     temp = findbyVS(w);
  1022.     if (temp < 0)
  1023.         return;
  1024. /*    if (!screens[scrn].lmflag)    */
  1025.         netwrite(screens[temp].port, ptr, len);
  1026.         netpush(screens[temp].port);                /* BYU 2.4.18 - for Diab systems? */
  1027. /*    else 
  1028.         {
  1029.         sprintf(screens[scrn].kbbuf,"%s",ptr);
  1030.         screens[scrn].kblen += len;
  1031.         if (screens[scrn].echo) parse(&screens[scrn],ptr,len);
  1032.         }*/
  1033.         
  1034. #else
  1035.     while (len--)
  1036.         putu(*ptr++);
  1037. #endif
  1038.   } /* RSsendstring */
  1039.  
  1040. void RSmargininfo
  1041.   (
  1042.     int w,
  1043.     int total, /* number of invisible character positions (screen width less visible width) */
  1044.     int current /* leftmost visible character position */
  1045.   )
  1046.   /* updates the horizontal scroll bar and associated variables
  1047.     to reflect the current view of the virtual screen within the
  1048.     specified window. */
  1049.   {
  1050.     RSlocal[w].leftmarg = current;            /* Adjust local vars */
  1051.     if (RSlocal[w].lcurrent != current)
  1052.         SetCtlValue(RSlocal[w].left, (RSlocal[w].lcurrent = current));
  1053.     if (RSlocal[w].lmax != total)
  1054.         SetCtlMax(RSlocal[w].left, (RSlocal[w].lmax = total));
  1055.   } /* RSmargininfo */
  1056.  
  1057. void RSbufinfo
  1058.   (
  1059.     int w, /* affected window */
  1060.     int total, /* number of lines of scrollback */
  1061.     int current, /* current topmost visible line */
  1062.     int bottom /* current bottommost visible line */
  1063.   )
  1064.   /* readjusts the vertical scroll bar and associated variables
  1065.     to reflect the current view of the virtual screen within the
  1066.     specified window. */
  1067.   {
  1068.     RSdata *RSthis;
  1069.     int newmax;
  1070.  
  1071.     RSthis = RSlocal + w;
  1072.     RSthis->topline = current;            /* Adjust local vars */
  1073.     if (RSthis->min != -total)
  1074.       {
  1075.         SetCtlMin(RSthis->scroll, (RSthis->min = -total));
  1076.         SetCtlValue(RSthis->scroll, (RSthis->current = current));
  1077.       } /* if */
  1078.     if (RSthis->current != current)
  1079.         SetCtlValue(RSthis->scroll, (RSthis->current = current));
  1080.     newmax = (VSgetlines(w) - 1) - (bottom - current);
  1081.     if (RSthis->max != newmax)
  1082.       {
  1083.         SetCtlMax(RSthis->scroll, (RSthis->max = newmax));
  1084.         SetCtlValue(RSthis->scroll, (RSthis->current = current));
  1085.       } /* if */
  1086.   } /* RSbufinfo */
  1087.  
  1088. GrafPtr RSgetwindow
  1089.   (
  1090.     int w
  1091.   )
  1092.   /* returns a pointer to the Mac window structure for the
  1093.     specified terminal window. */
  1094.   {
  1095.     return(RSlocal[w].window);
  1096.   } /* RSgetwindow */
  1097.  
  1098. void RSattach
  1099.   (
  1100.     int w,
  1101.     GrafPtr wind
  1102.   )
  1103.   /* attaches the specified window to a virtual screen, for
  1104.     use for displaying that screen. */
  1105.   {
  1106.     RSlocal[w].window = wind;
  1107.     RSlocal[w].selected = 0;
  1108.     RScurrent->cursorstate = 0;    /* BYU 2.4.11 - cursor off */
  1109.     SetPort(wind);
  1110. #if 1                                /* BYU */
  1111.     RSTextFont(FONT,FSIZE,0);            /* BYU */
  1112. #else
  1113.     TextFont(FONT);
  1114. #endif
  1115.  
  1116.     TextSize(FSIZE);
  1117.     if (!RScolor)
  1118.         TextMode(srcXor);            /* Xor mode*/
  1119.     else
  1120.         TextMode(srcCopy);
  1121.     RSw = -1;    /* make sure we don't write in wrong place */
  1122.   } /* RSattach */
  1123.  
  1124. void RSdetach
  1125.   (
  1126.     int w
  1127.   )
  1128.   /* detaches the window for the specified virtual screen. */
  1129.   {
  1130.     RSlocal[w].window = 0L;
  1131.     RSw = -1;    /* make sure we don't write in wrong place */
  1132.   } /* RSdetach */
  1133.  
  1134. int RSfindvwind
  1135.   (
  1136.     GrafPtr wind
  1137.   )
  1138.   /* returns the number of the virtual screen associated with
  1139.     the specified window, or -4 if not found. */
  1140.   {
  1141.     int
  1142.         i = 0;
  1143.     while ((RSlocal[i].window != wind) && (i < MaxRS))
  1144.         i++;
  1145.     if ((RSlocal[i].window == 0L) || (i >= MaxRS))
  1146.         return(-4);
  1147.     else
  1148.         return(i);
  1149.   } /* RSfindvwind */
  1150.  
  1151. int RSfindscroll                /* Find screen index by control*/
  1152.   (
  1153.     ControlHandle control,
  1154.     int *n
  1155.   )
  1156.   /* finds the window to which the given scroll bar belongs.
  1157.     Returns the window number in *n if found, and a function
  1158.     result of 1 for a vertical scroll bar, 2 for a horizontal
  1159.     one, or -1 if the window wasn't found. */
  1160.   {
  1161.   /* look for a vertical scroll bar */
  1162.     *n = 0;
  1163.     while ((*n < MaxRS) && (control != RSlocal[*n].scroll))
  1164.         (*n)++;
  1165.     if (*n < MaxRS)
  1166.         return (1); /* found it */
  1167.   /* look for a horizontal scroll bar */
  1168.     *n = 0;
  1169.     while ((*n < MaxRS) && (control != RSlocal[*n].left))
  1170.         (*n)++;
  1171.     if (*n < MaxRS)
  1172.         return (2); /* found it */
  1173.     return(-1); /* not found */
  1174.   } /* RSfindscroll */
  1175.  
  1176. void RSregnconv
  1177.   (
  1178.     RgnHandle regn,
  1179.     int *x1, /* left (output) */
  1180.     int *y1, /* top (output) */
  1181.     int *x2, /* right (output) */
  1182.     int *y2, /* bottom (output) */
  1183.     int fh, /* font character height */
  1184.     int fw /* font character width */
  1185.   )
  1186.   /* converts the bounding box of the specified QuickDraw region
  1187.     into units of character positions (using the specified character
  1188.     height and width) and returns the results in *x1, *y1, *x2 and *y2. */
  1189.   {
  1190.     HLock((Handle) regn);
  1191.     *y1 = ((*regn)->rgnBBox.top) / fh;
  1192.     *y2 = (((*regn)->rgnBBox.bottom) + fh - 1) / fh;
  1193.     *x1 = ((*regn)->rgnBBox.left) / fw;
  1194.     *x2 = (((*regn)->rgnBBox.right) + fw - 1) / fw;
  1195.     HUnlock((Handle) regn);
  1196.     if (*x1 < 0)
  1197.         *x1 = 0;
  1198.     if (*y1 < 0)
  1199.         *y1 = 0;
  1200.     if (*x2 < 0)
  1201.         *x2 = 0;
  1202.     if (*y2 < 0)
  1203.         *y2 = 0;
  1204. #ifdef WHONEEDSIT
  1205.     if (*x1> VSIw->maxwidth)
  1206.         *x1 = VSIw->maxwidth;
  1207.     if (*x2 > VSIw->maxwidth)
  1208.         *x2 = VSIw->maxwidth;
  1209.     if (*y1 > VSIw->lines)
  1210.         *y1 = VSIw->lines;
  1211.     if (*y2 > VSIw->lines)
  1212.         *y2 = VSIw->lines;
  1213. #endif WHONEEDSIT
  1214.   } /* RSregnconv */
  1215.  
  1216. int RSupdate
  1217.   (
  1218.     GrafPtr wind
  1219.   )
  1220.   /* does updating for the specified window, if it's one of mine.
  1221.     Returns zero iff it is. */
  1222.   {
  1223.     int w, x1, x2, y1, y2;
  1224.  
  1225.     w = RSfindvwind(wind);
  1226.     if (RSsetwind(w) < 0)
  1227.         return(-1); /* not one of mine */
  1228.     BeginUpdate(wind);
  1229.     RSregnconv /* find bounds of text area needing updating */
  1230.       (
  1231.         wind->visRgn,
  1232.         &x1, &y1, &x2, &y2,
  1233.         RScurrent->fheight, RScurrent->fwidth
  1234.       );
  1235.     VSredraw(w, x1, y1, x2, y2); /* draw that text */
  1236.   /* We must reset, less we risk looking UGLY as sin... */
  1237.     BackPat(qd.white);
  1238.     PenPat(qd.black);
  1239.     if (RScolor)
  1240.       {
  1241.         PmForeColor(0);
  1242.         PmBackColor(1);
  1243.       }
  1244.     else
  1245.       {
  1246.         ForeColor((long) RScolors[ RScurrent->color[0]]);        /* normal foreground */
  1247.         BackColor((long) RScolors[ RScurrent->color[1]]);        /* normal Background */
  1248.       } /* if */
  1249.     RSa = -1;
  1250.     PenMode(patOr);
  1251.     DrawGrowIcon(wind);
  1252.     PenMode(patCopy);
  1253.     DrawControls(wind);
  1254.     EndUpdate(wind);
  1255.     return(0);
  1256.   } /* RSupdate */
  1257.  
  1258. #ifdef FASTERCOMMENTED
  1259.  
  1260. RSupdprint(wind)
  1261.     WindowPeek wind;
  1262.   /* debugging routine: displays bounds (in character units) of
  1263.     update region of specified window. */
  1264.   {
  1265.     int x, y, z, w;
  1266.     char tbuf[50];
  1267.  
  1268.     RSregnconv(wind->updateRgn, &x, &y, &z, &w);
  1269.     sprintf(tbuf, "RSregnconv: %d,%d,%d,%d", x, y, z, w);
  1270.     putln(tbuf);
  1271.   } /* RSupdprint */
  1272.  
  1273. #endif
  1274.  
  1275. long getlocalmouse(wind)
  1276.     GrafPtr wind;
  1277.   /* returns the current mouse position in coordinates local
  1278.     to the specified window. Leaves the current grafPort set
  1279.     to that window. */
  1280.   {
  1281.     Point temp;
  1282.  
  1283.     SetPort(wind);
  1284.     GetMouse(&temp);
  1285.     return(*((long *) &temp));
  1286.   } /* getlocalmouse */
  1287.  
  1288. #define    Fwidthhalf    Fwidth/2
  1289.  
  1290. long normalize(in, w)
  1291.     Point in;
  1292.     int  w;
  1293.   /* converts in from a pixel position in local coordinates to
  1294.     a character cell position within the virtual screen corresponding
  1295.     to the specified window. Constrains the position to lie within
  1296.     the currently-visible region of the screen, autoscrolling the
  1297.     screen if necessary. */
  1298.   {
  1299.     if (in.v <0)
  1300.       {
  1301.         in.v = 0;
  1302.         VSscrolback(w, 1);
  1303.       } /* if */
  1304.     if (in.v > RSlocal[w].height)
  1305.       {
  1306.         in.v = RSlocal[w].height;
  1307.         VSscrolforward(w, 1);
  1308.       } /* if */
  1309.     in.v = in.v / Fheight;
  1310.  
  1311.     if (in.h < 0)
  1312.       {
  1313.         in.h = -1;
  1314.         VSscrolleft(w, 1);
  1315.       } /* if */
  1316.     if (in.h > RSlocal[w].width)
  1317.       {
  1318.         in.h = RSlocal[w].width;
  1319.         VSscrolright(w, 1);
  1320.       } /* if */
  1321.   /* in.h = (in.h + Fwidthhalf) / Fwidth - 1; */
  1322.   /* the MPW C 3.0 compiler has a bug in its register allocation */
  1323.   /* which keeps the above line from working. So, replace it with this: */
  1324.     in.h = in.h + Fwidthhalf;
  1325.     in.h = in.h / Fwidth - 1;
  1326.   /* note the bug has been fixed in the 3.1 compiler. */
  1327.   /* convert to virtual screen coordinates */
  1328.     in.v += RSlocal[w].topline;
  1329.     in.h += RSlocal[w].leftmarg;
  1330.     return(*((long *) &in));
  1331.   } /* normalize */
  1332.  
  1333. void RSselect
  1334.   (
  1335.     int w,
  1336.     long *pt, /* mouse-down position in local coordinates */
  1337.     short shift /* shift key is down (extend existing selection) or not */
  1338.   )
  1339.   /* called on a mouse-down in the text display area of the
  1340.     active window. Creates or extends the highlighted selection
  1341.     within that window, autoscrolling as appropriate if the user
  1342.     drags outside the currently visible part of the display. */
  1343.   {
  1344.     GrafPtr tempwndo;
  1345.     long curr;
  1346.  
  1347.     RSsetConst(w);
  1348.     tempwndo = RSlocal[w].window;
  1349.     if (RSlocal[w].selected)
  1350.       {
  1351.         if (!shift)
  1352.           {
  1353.           /* unhighlight current selection */
  1354.             RSinvText(w, *(Point *) &RSlocal[ w].anchor,
  1355.                 *(Point *) &RSlocal[w].last, &noConst);
  1356.           /* start new selection */
  1357.             curr = RSlocal[w].last = RSlocal[w].anchor = normalize(*pt, w);
  1358.             RSlocal[w].selected = 1;
  1359.           } /* if */
  1360.       }
  1361.     else
  1362.       {
  1363.       /* start new selection */
  1364.         curr = RSlocal[w].anchor = RSlocal[w].last = normalize(*pt, w);
  1365.         RSlocal[w].selected = 1;
  1366.       }
  1367.     while (StillDown())
  1368.       {
  1369.       /* wait for mouse position to change */
  1370.         while
  1371.           (((curr = normalize(getlocalmouse(tempwndo), w)) == RSlocal[w].last)
  1372.             && StillDown());
  1373.  
  1374.       /* toggle highlight state of text between current and last mouse positions */
  1375.         RSinvText(w, *(Point *) &curr, *(Point *) &RSlocal[w].last, &noConst);
  1376.         RSlocal[w].last = curr;
  1377.       } /* while */
  1378.  
  1379.     if  ( RSlocal[w].anchor == curr || RSlocal[w].anchor == RSlocal[w].last )
  1380.         {
  1381.         RSlocal[w].selected = 0; /* null selection */
  1382.         DisableItem(myMenus[Fil],FLprint);
  1383.         DisableItem(myMenus[Edit],EDcopy);
  1384.         DisableItem(myMenus[Edit],EDcopyt);
  1385.         }
  1386.  
  1387.     if (RSlocal[w].selected)      
  1388.         {
  1389.         EnableItem(myMenus[Fil],FLprint);
  1390.         EnableItem(myMenus[Edit],EDcopy);
  1391.         EnableItem(myMenus[Edit],EDcopyt);
  1392.         }
  1393.   } /* RSselect */
  1394.  
  1395. void RSactivate
  1396.   (
  1397.     int w
  1398.   )
  1399.   /* handles an activate event for the specified window. */
  1400.   {
  1401.     RSsetConst(w);
  1402.   /* display the grow icon */
  1403.     DrawGrowIcon(RSlocal[w].window);
  1404.   /* and activate the scroll bars */
  1405.     if (RSlocal[w].scroll != 0L)
  1406.         HiliteControl(RSlocal[w].scroll, 0);
  1407.     if (RSlocal[w].left != 0L)
  1408.         HiliteControl(RSlocal[w].left, 0);
  1409.   } /* RSactivate */
  1410.  
  1411. void RSdeactivate
  1412.   (
  1413.     int w
  1414.   )
  1415.   /* handles a deactivate event for the specified window. */
  1416.   {
  1417.     RSsetConst(w);
  1418.   /* update the appearance of the grow icon */
  1419.     DrawGrowIcon(RSlocal[w].window); 
  1420.   /* and deactivate the scroll bars */
  1421.     if (RSlocal[w].scroll != 0L)
  1422.         HiliteControl(RSlocal[w].scroll, 255);
  1423.     if (RSlocal[w].left != 0L)
  1424.         HiliteControl(RSlocal[w].left, 255);
  1425.   } /* RSdeactivate */
  1426.  
  1427. char **RSGetTextSel
  1428.   (
  1429.     int w, /* window to look at */
  1430.     int table /* nonzero for "table" mode, i e
  1431.         replace this many (or more) spaces with a single tab. */
  1432.   )
  1433.   /* returns the contents of the current selection as a handle,
  1434.     or nil if there is no selection. */
  1435.   {
  1436.     char **charh, *charp;
  1437.     int maxwid;
  1438.     long realsiz, VSgettext();
  1439.     char tempc[100];
  1440.     Point Anchor,Last;
  1441.  
  1442.     putln("In the routine");
  1443.     if (!RSlocal[w].selected)
  1444.         return(0L);    /* No Selection */
  1445.     maxwid = VSmaxwidth(w);
  1446.     Anchor = *((Point *) &RSlocal[w].anchor);
  1447.     Last = *((Point *) &RSlocal[w].last);
  1448.     realsiz = Anchor.v - Last.v;
  1449.     if (realsiz < 0)
  1450.         realsiz = - realsiz;
  1451.     realsiz ++;                                /* lines 2,3 selected can be 2 lines */
  1452.     realsiz *= (maxwid + 2);
  1453.     sprintf(tempc, "Size of block=%d", realsiz);
  1454.     putln(tempc);
  1455.     charh = NewHandle(realsiz);
  1456.     if (charh == 0L)
  1457.         return((char **) -1L);                /* Boo Boo return */
  1458.     HLock(charh);
  1459.     charp = *charh;
  1460.     realsiz = VSgettext(w, Anchor.h, Anchor.v, Last.h, Last.v,
  1461.         charp, realsiz, "\015", table);
  1462.     putln("unlocking");
  1463.     HUnlock(charh);
  1464.     SetHandleSize(charh, realsiz);
  1465.     sprintf(tempc, "Size of clip=%d", realsiz);
  1466.     putln(tempc);
  1467.     return(charh);
  1468.   }  /* RSGetTextSel */
  1469.  
  1470. void RSsetsize
  1471.   (
  1472.     int w,
  1473.     int v,
  1474.     int h
  1475.   )
  1476.   /* saves the new size settings for a window, and repositions
  1477.     the scroll bars accordingly. */
  1478.   {
  1479.     RSlocal[w].height = ((v - 16 + CVO) / Fheight) * Fheight;
  1480.     RSlocal[w].width = ((h - 16 + CHO) / Fwidth) * Fwidth;
  1481.     RSlocal[w].rheight = v - 16;
  1482.     RSlocal[w].rwidth = h - 16;
  1483.  
  1484. /*
  1485. *  Get rid of the scroll bars which were in the old size.
  1486. *  Hiding them causes the region to be updated later.
  1487. */
  1488.     if (RSlocal[w].scroll != NULL )
  1489.         HideControl(RSlocal[w].scroll);
  1490.     if (RSlocal[w].left != NULL ) 
  1491.         HideControl(RSlocal[w].left);
  1492.  
  1493.     DrawGrowIcon(RSlocal[w].window);            /* Draw in the necessary bugger */
  1494.  
  1495.   /* move the scroll bars to their new positions and sizes,
  1496.     and redisplay them */    
  1497.     if (RSlocal[w].scroll != NULL )
  1498.       {
  1499.         SizeControl(RSlocal[w].scroll, 16, (v - 13));
  1500.         MoveControl(RSlocal[w].scroll, (h - 15) + CHO, -1 + CVO);
  1501.         ShowControl(RSlocal[w].scroll);
  1502.       } /* if */
  1503.     if (RSlocal[w].left != NULL )
  1504.       {
  1505.         SizeControl(RSlocal[w].left, (h - 13), 16);
  1506.         MoveControl(RSlocal[w].left, -1 + CHO,  (v - 15) + CVO);
  1507.         ShowControl(RSlocal[w].left);
  1508.       } /* if */
  1509.     SetRect(&RSlocal[w].textrect, 0, 0, RSlocal[w].rwidth, RSlocal[w].rheight);
  1510.   } /* RSsetsize */
  1511.  
  1512. void RSdrawsep
  1513.   (
  1514.     int w,
  1515.     int y1,
  1516.     int draw /* 1 to draw the line, 0 to erase the existing line */
  1517.   )
  1518.   /* draws a dotted line separating the screen contents from the
  1519.     scrollback area. This is currently conditionally compiled to
  1520.     be a no-op. */
  1521.   {
  1522. #ifdef SEPLINE
  1523.     RSsetwind(w);
  1524.     PenPat(gray);
  1525.     if (draw)
  1526.         PenMode(srcCopy);
  1527.     else
  1528.         PenMode(srcXor);
  1529.     MoveTo(0, y1 * RScurrent->fheight);
  1530.     Line(RSlocal[w].width-1, 0);
  1531.     PenMode(srcOr);
  1532.     RSsetattr(0);
  1533. #else
  1534. #pragma unused(w, y1, draw)
  1535. #endif SEPLINE
  1536.   } /* RSdrawsep */
  1537.  
  1538. void RSfontmetrics
  1539.   (
  1540.     void
  1541.   )
  1542.   /* calculates various metrics for drawing text with selected font
  1543.     and size in current grafport into *RScurrent. */
  1544.   {
  1545.     FontInfo finforec;
  1546.     GrafPtr myGP;
  1547.  
  1548.     GetPort(&myGP); 
  1549.     GetFontInfo(&finforec);
  1550.     RScurrent->fascent = finforec.ascent;
  1551.     RScurrent->fheight = finforec.ascent + finforec.descent + finforec.leading /* +1 */;
  1552.     RScurrent->monospaced = (CharWidth('W') == CharWidth('i'));   
  1553. /*    RScurrent->monospaced = (CharWidth('W') == CharWidth('i') == CharWidth(' '));  */
  1554.  
  1555.     if (RScurrent->monospaced)
  1556.         RScurrent->fwidth = CharWidth('W'); 
  1557.     else 
  1558.         RScurrent->fwidth = finforec.widMax;
  1559.   }
  1560.  
  1561. void RSchangefont
  1562.   (
  1563.     int w,
  1564.     int fnum, /* new font ID or -1 for no change */
  1565.     int fsiz, /* new font size or 0 for no change */
  1566.     int resizwind /* should I resize window to keep same number of visible lines & cols */
  1567.   )
  1568.   {
  1569.     Rect pRect;
  1570.     int x1, x2, y1, y2, width, lines;
  1571.     int srw,srh;
  1572.     WStateData *wstate;
  1573.     WindowPeek wpeek;
  1574.  
  1575.     RSsetwind(w);
  1576.     srw = RScurrent->rwidth;
  1577.     srh = RScurrent->rheight;
  1578.  
  1579.     if (fnum != -1)
  1580.       {
  1581. #if 1                                /* thanx to Jim@BYU */
  1582.         RSTextFont(fnum,fsiz,0);    /* thanx to Jim@BYU */
  1583. #else
  1584.         TextFont(fnum);
  1585. #endif
  1586.         RScurrent->fnum = fnum;
  1587.       } /* if */
  1588.     if (fsiz)
  1589.       {
  1590.         TextSize(fsiz);
  1591.         RScurrent->fsiz = fsiz;
  1592.       } /* if */
  1593.     RSfontmetrics();
  1594.  
  1595.     width = VSmaxwidth(w) + 1;
  1596.     lines = VSgetlines(w);
  1597.     if (!resizwind)
  1598.       {
  1599.       /* round window size to new character cell dimensions */
  1600.         RScurrent->height =
  1601.             ((RScurrent->rheight) / RScurrent->fheight) * RScurrent->fheight;
  1602.         RScurrent->width =
  1603.             ((RScurrent->rwidth + CHO) / RScurrent->fwidth ) * RScurrent->fwidth
  1604.                 - CHO;
  1605.       }
  1606.     else
  1607.       {
  1608.       /* resize window to preserve its dimensions in character cell units */
  1609.         VSgetrgn(w, &x1, &y1, &x2, &y2);
  1610.         RScurrent->rwidth =
  1611.             RScurrent->width = (x2 - x1 + 1) * RScurrent->fwidth - CHO;
  1612.         RScurrent->rheight =
  1613.             RScurrent->height= (y2 - y1 + 1) * RScurrent->fheight;
  1614.       } /* if */
  1615.  
  1616.     if (RScurrent->rwidth > MAXWINDOWWIDTH - 16 - CHO)
  1617.           RScurrent->rwidth = MAXWINDOWWIDTH - 16 - CHO;
  1618.     if (RScurrent->rheight > MAXWINDOWHEIGHT - 16)
  1619.           RScurrent->rheight = MAXWINDOWHEIGHT - 16;
  1620.     
  1621.     SizeWindow
  1622.       (
  1623.         RScurrent->window,
  1624.         RScurrent->rwidth + 16, RScurrent->rheight+16,
  1625.         FALSE
  1626.       ); /*  TRUE if done right */
  1627.     RSsetsize(w, RScurrent->rheight + 16, RScurrent->rwidth + 16);
  1628.  
  1629.     wpeek = (WindowPeek) RScurrent->window;
  1630.  
  1631.     HLock(wpeek->dataHandle);
  1632.     wstate = (WStateData *) *wpeek->dataHandle;
  1633.  
  1634.     movmem(&wstate->stdState, &pRect, 8);
  1635.     pRect.right = pRect.left + MAXWINDOWWIDTH;
  1636.     if (pRect.right > screenRect.right)
  1637.         pRect.right = screenRect.right;
  1638.     pRect.bottom = pRect.top + MAXWINDOWHEIGHT;
  1639.     movmem(&pRect, &wstate->stdState, 8);
  1640.  
  1641.     VSgetrgn(w, &x1, &y1, &x2, &y2);
  1642.     VSsetrgn(w, x1, y1,
  1643.         (int) (x1 + (RScurrent->rwidth ) / RScurrent->fwidth - 1),
  1644.         (int) (y1 + (RScurrent->rheight) / RScurrent->fheight - 1));
  1645.     VSgetrgn(w, &x1, &y1, &x2, &y2);        /* Get new region */
  1646.     
  1647.     DrawGrowIcon(RScurrent->window);
  1648.     VSredraw(w, 0, 0, x2 - x1 + 1, y2 - y1 + 1); /* redraw newly-revealed area, if any */
  1649.     ValidRect(&RScurrent->window->portRect); /* no need to do it again */
  1650.     DrawControls(RScurrent->window);
  1651.   } /* RSchangefont */
  1652.  
  1653. int RSgetfont
  1654.   (
  1655.     int w, /* which window */
  1656.     int *pfnum, /* where to return font ID */
  1657.     int *pfsiz /* where to return font size */
  1658.   )
  1659.   /* returns the current font ID and size setting for the specified window. */
  1660.   {
  1661. /*
  1662. *  Bug fix.  RSsetwind's error conditions are all < 0.  There is a success condition == 1.
  1663. *  TK 12/17/88
  1664. */
  1665.     if (0 > RSsetwind(w))
  1666.         return -1;
  1667.     *pfnum = RScurrent->fnum;
  1668.     *pfsiz = RScurrent->fsiz;
  1669.     return(0);
  1670.   } /* RSgetfont */
  1671.  
  1672. int RSnewwindow
  1673.   (
  1674.     RectPtr wDims, /* window bounds in pixels */
  1675.     int scrollback, /* number of lines to save off top */
  1676.     int width, /* number of characters per text line (80 or 132) */
  1677.     int lines, /* number of text lines */
  1678.     char *name, /* window name */
  1679.     int wrapon, /* autowrap on by default */
  1680.     int fnum, /* ID of font to use initially */
  1681.     int fsiz, /* size of font to use initially */
  1682.     int showit, /* window initially visible or not */
  1683.     int goaway, /* NCSA 2.5 */
  1684.     int forcesave        /* NCSA 2.5: force screen save */
  1685.   )
  1686.   /* creates a virtual screen and a window to display it in. */
  1687.   {
  1688.     GrafPort gp; /* temp port for getting text parameters */
  1689.     int w;
  1690.  
  1691.     Rect pRect;
  1692.     int wheight, wwidth;
  1693.     long VSwhereis();
  1694.     WStateData *wstate;
  1695.     WindowPeek wpeek;
  1696.  
  1697.   /* create the virtual screen */
  1698.     w = VSnewscreen(scrollback, (scrollback != 0), /* NCSA 2.5 */
  1699.         width,1, forcesave);    /* NCSA 2.5 */
  1700.     if (w < 0)
  1701.       {
  1702.         putln("Couldn't open Virtual Screen");
  1703.         return(-1);
  1704.       }
  1705.     RScurrent = RSlocal + w;
  1706.  
  1707.     RScurrent->fnum = fnum;
  1708.     RScurrent->fsiz = fsiz;
  1709.  
  1710.     OpenPort(&gp);
  1711. #if 1                            /* thanx to Jim@BYU */
  1712.     RSTextFont(fnum,fsiz,0);    /* thanx to Jim@BYU */
  1713. #else
  1714.     TextFont(fnum);
  1715. #endif
  1716.     TextSize(fsiz);
  1717.     RSfontmetrics();
  1718.     ClosePort(&gp);
  1719.  
  1720.     if ((wDims->right - wDims->left) > MAXWINDOWWIDTH)
  1721.         wDims->right = wDims->left + MAXWINDOWWIDTH;
  1722.     if ((wDims->bottom - wDims->top) > MAXWINDOWHEIGHT)
  1723.         wDims->bottom = wDims->top + MAXWINDOWHEIGHT;
  1724.     wwidth = wDims->right - wDims->left;
  1725.     wheight = wDims->bottom - wDims->top;
  1726.  
  1727.   /* create the window */
  1728.     if (!RScolor)
  1729.         RScurrent->window = newwindow(0L, wDims, name, showit?TRUE:FALSE, 8,
  1730.             (WindowPtr) -1L,goaway?TRUE:FALSE, (long)w);
  1731.     else
  1732.       {
  1733.         RScurrent->window = newcwindow(0L, wDims, name, showit?TRUE:FALSE, 8,
  1734.             (WindowPtr) -1L, goaway?TRUE:FALSE, (long)w);
  1735.                     /* the screen is not there until we can see it..... */
  1736.         HLock((Handle) RSctab);
  1737.         (*RSctab)->ctSize = 4;
  1738.         RScurrent->RGBs[0].red  =(*RSctab)->ctTable[0].rgb.red        =     0;
  1739.         RScurrent->RGBs[0].green=(*RSctab)->ctTable[0].rgb.green    =     0;
  1740.         RScurrent->RGBs[0].blue =(*RSctab)->ctTable[0].rgb.blue        =     0;
  1741.         RScurrent->RGBs[1].red  =(*RSctab)->ctTable[1].rgb.red        = 65535;
  1742.         RScurrent->RGBs[1].green=(*RSctab)->ctTable[1].rgb.green    = 65535;
  1743.         RScurrent->RGBs[1].blue =(*RSctab)->ctTable[1].rgb.blue        = 65535;
  1744.         RScurrent->RGBs[2].red  =(*RSctab)->ctTable[2].rgb.red        =     0;
  1745.         RScurrent->RGBs[2].green=(*RSctab)->ctTable[2].rgb.green    = 61183;
  1746.         RScurrent->RGBs[2].blue =(*RSctab)->ctTable[2].rgb.blue        = 11060;
  1747.         RScurrent->RGBs[3].red  =(*RSctab)->ctTable[3].rgb.red        = 61183;
  1748.         RScurrent->RGBs[3].green=(*RSctab)->ctTable[3].rgb.green    =  2079;
  1749.         RScurrent->RGBs[3].blue =(*RSctab)->ctTable[3].rgb.blue        =  4938;
  1750.         HUnlock((Handle) RSctab);
  1751.  
  1752.         RScurrent->pal = NewPalette(4, RSctab, pmCourteous, 0);
  1753.         SetPalette(RScurrent->window, RScurrent->pal, TRUE);
  1754.       } /* if */
  1755.  
  1756.     if (RScurrent->window == 0L)
  1757.       {
  1758.         printf("Couldn't open Real Window");
  1759.         return(-2);
  1760.       }
  1761.  
  1762.     SetPort(RScurrent->window);
  1763.     SetOrigin(CHO, CVO);            /* Cheap way to correct left margin problem */
  1764.  
  1765.     wpeek = (WindowPeek) RScurrent->window;
  1766.  
  1767.     HLock(wpeek->dataHandle);
  1768.     wstate = (WStateData *) *wpeek->dataHandle;
  1769.  
  1770.     movmem(wDims, &wstate->userState, 8);
  1771.     pRect.top = wDims->top;
  1772.     pRect.left = wDims->left;
  1773.     pRect.right = pRect.left + MAXWINDOWWIDTH;
  1774.     if (pRect.right > screenRect.right)
  1775.         pRect.right = screenRect.right;
  1776.  
  1777.     pRect.bottom = pRect.top + MAXWINDOWHEIGHT;
  1778.     movmem(&pRect, &wstate->stdState, 8);
  1779.  
  1780.   /* create scroll bars for window */
  1781.     pRect.top = -1 + CVO;
  1782.     pRect.bottom = wheight - 14 + CVO;
  1783.     pRect.left = wwidth - 15 + CHO;
  1784.     pRect.right = wwidth + CHO;
  1785.     RScurrent->scroll = newcontrol(RScurrent->window, &pRect, "", FALSE,
  1786.         0, 0, 0, 16, 1L);
  1787.     if (RScurrent->scroll == 0L)
  1788.       {
  1789.         printf("Couldn't Make Vertical Scroll Bar");
  1790.         return(-3);
  1791.       }
  1792.  
  1793.     pRect.top = wheight - 15 + CVO;
  1794.     pRect.bottom = wheight + CVO;
  1795.     pRect.left = -1 + CHO;
  1796.     pRect.right = wwidth - 14 + CHO;
  1797.     RScurrent->left = newcontrol(RScurrent->window, &pRect, "", FALSE,
  1798.         0, 0, 0, 16, 1L);
  1799.     if (RScurrent->left == 0L)
  1800.       {
  1801.         printf("Couldn't Make Horizontal Scroll Bar");
  1802.         return(-3);
  1803.       }
  1804.  
  1805.     RScurrent->skip = 0; /* not skipping output initially */
  1806.     RScurrent->max = 0; /* scroll bar settings will be properly initialized by subsequent call to VSsetrgn */
  1807.     RScurrent->min = 0;
  1808.     RScurrent->current = 0;
  1809.     RScurrent->lmax = 0;
  1810.     RScurrent->lmin = 0;
  1811.     RScurrent->lcurrent = 0;
  1812.     RScurrent->selected = 0; /* no selection initially */
  1813.     RScurrent->cursorstate = 0;    /* BYU 2.4.11 - cursor off initially */
  1814.  
  1815.     RSsetsize(w, wheight, wwidth);
  1816.     VSsetlines(w, lines);
  1817.     VSsetrgn(w, 0, 0, ((wwidth - 16 + CHO) / Fwidth -1),
  1818.         ((wheight - 16 + CVO) / Fheight - 1));
  1819.  
  1820. #if 1                                /* thankx to Jim@BYU */
  1821.     RSTextFont(RScurrent->fnum,0);    /* thankx to Jim@BYU */
  1822. #else
  1823.     TextFont(RScurrent->fnum);
  1824. #endif
  1825.     TextSize(RScurrent->fsiz);                /* 9 point*/
  1826.     if (!RScolor)
  1827.         TextMode(srcXor);            /* Xor mode*/
  1828.     else
  1829.         TextMode(srcCopy);
  1830.  
  1831.     if (wrapon)
  1832.       /* turn on autowrap */
  1833.         VSwrite(w, "\033[?7h",5);
  1834.  
  1835.     return(w);
  1836.   } /* RSnewwindow */
  1837.  
  1838. void RSkillwindow
  1839.   (
  1840.     int w
  1841.   )
  1842.   /* closes a terminal window. */
  1843.   {
  1844.     VSdetach(w);        /* Detach the virtual screen */
  1845.     KillControls(RSlocal[w].window);  /* Get rid of those little slidy things */
  1846.     DisposeWindow(RSlocal[w].window);    /* Get rid of the actual window */
  1847.     RSdetach(w);        /* Detach from the table */
  1848.   }
  1849.  
  1850. void RSzoom
  1851.   (
  1852.     GrafPtr window, /* window to zoom */
  1853.     int code, /* inZoomIn or inZoomOut */
  1854.     int shifted /* bring to front or not */
  1855.   )
  1856.   /* called after a click in the zoom box, to zoom a terminal window. */
  1857.   {
  1858.     int w;
  1859.     int h, v, x1, x2, y1, y2;
  1860.  
  1861.     SetPort(window);
  1862.   /* EraseRect(&window->portRect); */
  1863.     ZoomWindow(window, code, shifted);
  1864.     EraseRect(&window->portRect);            /* BYU 2.4.15 */
  1865.  
  1866.   /* get new window size */
  1867.     h = window->portRect.right - window->portRect.left;
  1868.     v = window->portRect.bottom - window->portRect.top;
  1869.  
  1870.     w = RSfindvwind(window); /* which window is it, anyway */
  1871.     RSsetsize(w, v, h); /* save new size settings and update scroll bars */
  1872.   /* update the visible region of the virtual screen */
  1873.     VSgetrgn(w, &x1, &y1, &x2, &y2);
  1874.     VSsetrgn(w, x1, y1, (x1 + (h - 16 + CHO) / Fwidth -1),
  1875.         (y1 + (v - 16 + CVO) / Fheight - 1));
  1876.     VSgetrgn(w, &x1, &y1, &x2, &y2);        /* Get new region */
  1877.   /* refresh the part which has been revealed, if any */
  1878.     VSredraw(w, 0, 0, x2 - x1 + 1, y2 - y1 + 1); 
  1879.   /* window contents are now completely valid */
  1880.     ValidRect(&window->portRect);
  1881.   } /* RSzoom */
  1882.  
  1883. /*
  1884. *  This routine is called when the user presses the grow icon, or when the size of
  1885. *  the window needs to be adjusted (where==NULL, modifiers==0).
  1886. *  It limits the size of the window to a legal range.
  1887. */
  1888.  
  1889. void RSsize
  1890.   (
  1891.     GrafPtr window,
  1892.     long *where,
  1893.     int modifiers
  1894.   )
  1895.   {
  1896.     Rect SizRect;
  1897.     long size;
  1898.     int w, width, lines;
  1899.     int tw, h, v, x1, x2, y1, y2, th;
  1900.  
  1901.     if ((w = RSfindvwind(window)) < 0)
  1902.         return;
  1903.     if (modifiers & cmdKey)
  1904.         return ;        /* don't allow command-grow */
  1905.     
  1906.     SetPort(window);
  1907.  
  1908.     width = VSmaxwidth(w) + 1;
  1909.     lines = VSgetlines(w);
  1910.     tw = MAXWINDOWWIDTH; /* don't allow window to be wider than virtual screen */
  1911. #ifdef LIMIT_WIDTH
  1912.     if (tw > screenRect.right)
  1913.         tw = screenRect.right - window->portRect.left - CHO;
  1914. #endif    LIMIT_WIDTH
  1915.     if (modifiers & optionKey)
  1916.       /* changing size of virtual screen */
  1917.         th = screenRect.bottom;
  1918.     else
  1919.       /* don't allow window to be taller than virtual screen */
  1920.         th = MAXWINDOWHEIGHT + 1;
  1921.     SetRect(&SizRect, 48, 48, tw + 1, th);
  1922.     
  1923.     if (where)
  1924.       {                            /* grow icon actions */
  1925.         size = growwindow(window, (Point *) where, &SizRect);
  1926.         if (size != 0L)
  1927.           {
  1928.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  1929.             h = window->portRect.right - window->portRect.left;
  1930.             v = window->portRect.bottom - window->portRect.top;
  1931.           }
  1932.         else
  1933.             return;                            /* user skipped growing */
  1934.       }
  1935.     else
  1936.       {                                    /* just resize the window */
  1937.         h = window->portRect.right - window->portRect.left;    /* same width */
  1938.         v = (Fheight) * VSgetlines(w) + 16;                    /* new height */
  1939.         SizeWindow(window, h, v, FALSE);                    /* change it */
  1940.       } /* if */
  1941.     RSsetsize(w, v, h); /* save new size settings and update scroll bars */
  1942.   /* update the visible region of the virtual screen */
  1943.     VSgetrgn(w, &x1, &y1, &x2, &y2);
  1944.     VSsetrgn(w, x1, y1, (x1 + (h - 16 + CHO) / Fwidth - 1),
  1945.         (y1 + (v - 16) / Fheight - 1));
  1946.     VSgetrgn(w, &x1, &y1, &x2, &y2);        /* Get new region */
  1947.     if (modifiers & optionKey)
  1948.         VSsetlines(w, y2 - y1 + 1); /* change height of virtual screen */
  1949.   /* refresh the part which has been revealed, if any */
  1950.     VSredraw(w, 0, 0, x2 - x1 + 1, y2 - y1 + 1);
  1951.   /* window contents are now completely valid */
  1952.     ValidRect(&window->portRect);
  1953.     return;
  1954.   } /* RSsize */
  1955.  
  1956. int RSclick
  1957.   (
  1958.     GrafPtr window, /* which window */
  1959.     long *where, /* position in global coordinates */
  1960.     int shifted, /* shift key was down */
  1961.     int optioned /* option key was down */
  1962.   )
  1963.   /* handles a click in a terminal window. */
  1964.   {
  1965.     ControlHandle ctrlh;
  1966.     int w, part, part2, x1, x2, y1, y2;
  1967.  
  1968.     w = RSfindvwind(window);
  1969.     if (w < 0)
  1970.         return -1; /* what the heck is going on here?? */
  1971.     SetPort(window);
  1972.     GlobalToLocal((Point *) where);
  1973.     part = findcontrol((Point *) where, window, &ctrlh);
  1974.     if (part != 0)
  1975.         switch (part)
  1976.           {
  1977.             case inThumb:
  1978.                 part2 = trackcontrol(ctrlh, (Point *) where, 0L);
  1979.                 if (part2 == inThumb)
  1980.                   {
  1981.                     part = GetCtlValue(ctrlh);
  1982.                     if (ctrlh == RSlocal[w].scroll)
  1983.                       {
  1984.                       /* scroll visible region vertically */
  1985.                         VSgetrgn(w, &x1, &y1, &x2, &y2);
  1986.                         VSsetrgn(w, x1, part, x2, part + (y2 - y1));
  1987.                       }
  1988.                     else
  1989.                       { /* ctrlh must be .left */
  1990.                       /* scroll visible region horizontally */
  1991.                         VSgetrgn(w, &x1, &y1, &x2, &y2);
  1992.                         VSsetrgn(w, part, y1, part + (x2 - x1), y2);
  1993.                       } /* if */
  1994.                   } /* if */
  1995.                 break;
  1996.             case inUpButton:
  1997.             case inDownButton:
  1998.             case inPageUp:
  1999.             case inPageDown:
  2000.                 part2 = trackcontrol(ctrlh, (Point *) where, (ProcPtr) ScrollProc);
  2001.     /*            InvalRect(&(**RSlocal->scroll).contrlRect); */  /* cheap fix */
  2002.                 break;
  2003.             default:
  2004.                 break;
  2005.           } /* switch */
  2006.     else
  2007.       {
  2008.         if (optioned) 
  2009.           {
  2010.           /* send host the appropriate sequences to move the cursor
  2011.             to the specified position */
  2012.             Point x;
  2013.             (*(long *) &x) = normalize(*where, w);
  2014.             VSpossend(w, x.h, x.v, screens[scrn].echo);
  2015.           }
  2016.         else
  2017.             RSselect(w, where, shifted);
  2018.       } /* if */
  2019.     return
  2020.         0;
  2021.   } /* RSclick */
  2022.  
  2023. pascal void ScrollProc(control, part)
  2024.     short part;
  2025.     ControlHandle control;
  2026.   /* scroll-tracking routine which does continuous scrolling of visible
  2027.      region. */
  2028.   {
  2029.     int w, kind, x1, y2, x2, y1;
  2030.  
  2031.     kind = RSfindscroll(control, &w);
  2032.     VSgetrgn(w, &x1, &y1, &x2, &y2);
  2033.  
  2034.     if (kind == 2)
  2035.       { /* horizontal scroll bar */
  2036.         switch (part)
  2037.           {
  2038.             case inUpButton:                            /* Up is left */
  2039.                 VSscrolleft(w, 1);
  2040.                 break;
  2041.             case inDownButton:                            /* Down is right */
  2042.                 VSscrolright(w, 1);
  2043.                 break;
  2044.             case inPageUp:
  2045.                 VSscrolleft(w, x2 - x1); /* scroll a whole windowful */
  2046.                 break;
  2047.             case inPageDown:
  2048.                 VSscrolright(w, x2 - x1); /* scroll a whole windowful */
  2049.                 break;
  2050.             default:
  2051.                 break;
  2052.           } /* switch */
  2053.       }
  2054.     else if (kind == 1)
  2055.       { /* vertical scroll bar */
  2056.         switch (part)
  2057.           {
  2058.             case inUpButton:
  2059.                 VSscrolback(w, 1);
  2060.                 break;
  2061.             case inDownButton:
  2062.                 VSscrolforward(w, 1);
  2063.                 break;
  2064.             case inPageUp:
  2065.                 VSscrolback(w, y2 - y1); /* scroll a whole windowful */
  2066.                 break;
  2067.             case inPageDown:
  2068.                 VSscrolforward(w, y2 - y1); /* scroll a whole windowful */
  2069.                 break;
  2070.             default:
  2071.                 break;
  2072.           } /* switch */
  2073.       } /* if */
  2074.   } /* ScrollProc */
  2075.  
  2076. void RShide
  2077.   (
  2078.     int w
  2079.   )
  2080.   /* hides a terminal window. */
  2081.   {
  2082.     if (RSsetwind(w) < 0)
  2083.         return;
  2084.     HideWindow(RScurrent->window);
  2085.   } /* RShide */
  2086.  
  2087. void RSshow
  2088.   (
  2089.     int w
  2090.   )
  2091.   /* reveals a hidden terminal window. */
  2092.   {
  2093.     if (RSsetwind(w) < 0)
  2094.         return;
  2095.     ShowWindow(RScurrent->window);
  2096.   } /* RSshow */
  2097.  
  2098.  
  2099. #ifdef NCSA_TELNET
  2100. /* color selection dialog */
  2101.  
  2102. /* globals for communicating with handlers for dialog user items */
  2103. int
  2104.     RScpromptnum = 0, /* number of window for which settings are being displayed/changed */
  2105.     RScfontsize = 0; /* currently-chosen font size */
  2106. Str255
  2107.     RScfontname; /* currently-chosen font name */
  2108.  
  2109. #ifdef PROMPTFONT
  2110. /* code to include font selection in color selection dialog */
  2111.  
  2112. pascal void RSdrawsize(wind, item)
  2113.     GrafPtr wind;
  2114.     int item;
  2115.   /* handler for a dialog user item--frames the item with a shadowed
  2116.     border and displays the currently-chosen font size within it. */
  2117.   {
  2118.     short itemType;
  2119.     Rect ibox;
  2120.     char **itemh;
  2121.     RGBColor rgb;
  2122.     char temp[50];
  2123.  
  2124.     GetDItem(wind, item, &itemType, &itemh, &ibox);
  2125.  
  2126.     EraseRect(&ibox);
  2127.     MoveTo(ibox.left, ibox.top + 12);
  2128.     sprintf(temp, "%d", RScfontsize);
  2129.     drawstring(temp);
  2130.     FrameRect(&ibox);
  2131.     MoveTo(ibox.right, ibox.top + 1);
  2132.     LineTo(ibox.right, ibox.bottom);
  2133.     LineTo(ibox.left, ibox.bottom);
  2134.   } /* RSdrawsize */
  2135.  
  2136. pascal void RSdrawfont(wind, item)
  2137.     GrafPtr wind;
  2138.     int item;
  2139.   /* handler for a dialog user item--frames the item with a shadowed
  2140.     border and draws the name of the currently-chosen font within it. */
  2141.   {
  2142.     int itemType;
  2143.     Rect ibox;
  2144.     char **itemh;
  2145.     RGBColor rgb;
  2146.  
  2147.     GetDItem(wind, item, &itemType, &itemh, &ibox);
  2148.  
  2149.     EraseRect(&ibox);
  2150.     MoveTo(ibox.left, ibox.top + 12);
  2151.     drawstring(&RScfontname);
  2152.     FrameRect(&ibox);
  2153.     MoveTo(ibox.right, ibox.top+1);
  2154.     LineTo(ibox.right, ibox.bottom);
  2155.     LineTo(ibox.left, ibox.bottom);
  2156.   } /* RSdrawfont */
  2157.  
  2158. #endif PROMPTFONT
  2159.  
  2160. pascal void RScboxdraw(wind, item)
  2161.     GrafPtr wind;
  2162.     short item;
  2163.   /* handler for a dialog user item--draws a box around the item. */
  2164.   {
  2165.     short itemType;
  2166.     Rect ibox;
  2167.     char **itemh;
  2168.  
  2169.     GetDItem(wind, item, &itemType, &itemh, &ibox);
  2170.     InsetRect(&ibox, -2, -2);
  2171.     FrameRect(&ibox);
  2172.   } /* RScboxdraw */
  2173.  
  2174. pascal void RScdraw(wind, item)
  2175.     GrafPtr wind;
  2176.     short item;
  2177.   /* handler for a dialog user item representing one of the
  2178.     currently-chosen colors. Fills in the item rectangle with
  2179.     the color. */
  2180.   {
  2181.     short itemType;
  2182.     Rect ibox;
  2183.     char **itemh;
  2184.     RGBColor rgb;
  2185.  
  2186.     GetDItem(wind, item, &itemType, &itemh, &ibox);
  2187.     GetForeColor(&rgb);
  2188.     RGBForeColor(&RSlocal[RScpromptnum].RGBs[item - 3]); /* color corresponding to item */
  2189.     PaintRect(&ibox);
  2190.     RGBForeColor(&rgb); /* restore previous foreground color */
  2191.   } /* RScdraw */
  2192.  
  2193. int RScprompt
  2194.   (
  2195.     int w,
  2196.     int (*FilterProc)()
  2197.   )
  2198.   /* puts up the dialog that lets the user examine and change the color
  2199.     settings for the specified window. */
  2200.   {
  2201.     short
  2202.         itemType;
  2203.     short
  2204.         item, x;
  2205.     long
  2206.         sresult = 1,
  2207.         fresult = 1;
  2208.  
  2209.     static char
  2210.         *cprompt = "\pChoose a color:";
  2211.  
  2212.     Rect ibox;
  2213.     char **itemh;
  2214.     RGBColor rgb2;
  2215.     DialogPtr dlog;
  2216.     Point pt;
  2217. #ifdef PROMPTFONT
  2218.     short size, num;
  2219.     long result;
  2220.     char sizetemp[10];
  2221.     Rect sizebox, fontbox, fnambox, snambox;
  2222.     MenuHandle fontMH, sizeMH;
  2223. #endif PROMPTFONT
  2224.  
  2225.     pt.h = 0;
  2226.     pt.v = 0;
  2227.  
  2228.     RScpromptnum = w;
  2229.  
  2230. #ifdef PROMPTFONT
  2231.   /* get name of currently-chosen font */
  2232.     RScfontsize = RSlocal[w].fsiz;
  2233.     getfontname(RSlocal[w].fnum, &RScfontname);
  2234. #endif PROMPTFONT
  2235.  
  2236.   /* open the selection dialog */
  2237.     dlog = GetNewDialog(1001, (Ptr) 0L, (WindowPtr) -1L);
  2238.     SetPort(dlog);
  2239.  
  2240. #ifdef PROMPTFONT
  2241.   /* create the pop-up menus for choosing font and size */
  2242.     fontMH = newmenu(63, "\PFontPopUp");
  2243.     AddResMenu(fontMH, 'FONT');
  2244.     sizeMH = newmenu(64, "\PSizePopUp");
  2245.     appendmenu(sizeMH, "\P7;9;10;12;18;24;36");
  2246.     InsertMenu(fontMH, -1);
  2247.     InsertMenu(sizeMH, -1);
  2248. #endif PROMPTFONT
  2249.  
  2250.     GetDItem(dlog, 3, &itemType, &itemh, &ibox);
  2251.     SetDItem(dlog, 3, itemType, (Handle) RScdraw, &ibox);
  2252.  
  2253.     GetDItem(dlog, 4, &itemType, &itemh, &ibox);
  2254.     SetDItem(dlog, 4, itemType, (Handle) RScdraw, &ibox);
  2255.  
  2256.     GetDItem(dlog, 5, &itemType, &itemh, &ibox);
  2257.     SetDItem(dlog, 5, itemType, (Handle) RScdraw, &ibox);
  2258.  
  2259.     GetDItem(dlog, 6, &itemType, &itemh, &ibox);
  2260.     SetDItem(dlog, 6, itemType, (Handle) RScdraw, &ibox);
  2261.  
  2262.     GetDItem(dlog, 11, &itemType, &itemh, &ibox);
  2263.     SetDItem(dlog, 11, itemType, (Handle) RScboxdraw, &ibox);
  2264.  
  2265.     GetDItem(dlog, 12, &itemType, &itemh, &ibox);
  2266.     SetDItem(dlog, 12, itemType, (Handle) RScboxdraw, &ibox);
  2267.  
  2268.     GetDItem(dlog, 13, &itemType, &itemh, &ibox);
  2269.     SetDItem(dlog, 13, itemType, (Handle) RScboxdraw, &ibox);
  2270.  
  2271.     GetDItem(dlog, 14, &itemType, &itemh, &ibox);
  2272.     SetDItem(dlog, 14, itemType, (Handle) RScboxdraw, &ibox);
  2273.  
  2274. #ifdef PROMPTFONT
  2275.     GetDItem(dlog, 11, &itemType, &itemh, &fnambox);
  2276.  
  2277.     GetDItem(dlog, 12, &itemType, &itemh, &fontbox);
  2278.     SetDItem(dlog, 12, itemType, (Handle) RSdrawfont, &fontbox);
  2279.     LocalToGlobal(&fontbox); /* for positioning pop-up menu */
  2280.  
  2281.     GetDItem(dlog, 13, &itemType, &itemh, &snambox);
  2282.  
  2283.     GetDItem(dlog, 14, &itemType, &itemh, &sizebox);
  2284.     SetDItem(dlog, 14, itemType, (Handle) RSdrawsize, &sizebox);
  2285.     LocalToGlobal(&sizebox); /* for positioning pop-up menu */
  2286. #endif PROMPTFONT
  2287.  
  2288.     item = 0;
  2289.     while (item !=1 && item !=2)
  2290.       {
  2291.         ModalDialog((ModalFilterProcPtr) FilterProc, &item);
  2292.         switch (item)
  2293.           {
  2294.             case 3:
  2295.                 x = GetColor(pt, cprompt, &RSlocal[w].RGBs[0], &rgb2);
  2296.                 if (x)
  2297.                     RSlocal[w].RGBs[0] = rgb2;
  2298.                 break;
  2299.  
  2300.             case 4:
  2301.                 x = GetColor(pt, cprompt, &RSlocal[w].RGBs[1], &rgb2);
  2302.                 if (x)
  2303.                     RSlocal[w].RGBs[1] = rgb2;
  2304.                 break;
  2305.  
  2306.             case 5:
  2307.                 x = GetColor(pt, cprompt, &RSlocal[w].RGBs[2], &rgb2);
  2308.                 if (x)
  2309.                     RSlocal[w].RGBs[2] = rgb2;
  2310.                 break;
  2311.  
  2312.             case 6:
  2313.                 x = GetColor(pt, cprompt, &RSlocal[w].RGBs[3], &rgb2);
  2314.                 if (x)
  2315.                     RSlocal[w].RGBs[3] = rgb2;
  2316.                 break;
  2317.  
  2318. #ifdef PROMPTFONT
  2319.             case 12:
  2320.                 InvertRect(&fnambox);
  2321.                 result = PopUpMenuSelect(fontMH, fontbox.top, fontbox.left, (short) fresult);
  2322.                 result = result & 0xffff;
  2323.                 InvertRect(&fnambox);
  2324.  
  2325.                 if (result > 0)
  2326.                   {
  2327.                     getitem(fontMH, (short) result, &RScfontname);
  2328.                     RSdrawfont(dlog, 12);
  2329.                     fresult = result;
  2330.                   } /* if */
  2331.                 break;
  2332.             case 14:
  2333.                 InvertRect(&snambox);
  2334.                 result = PopUpMenuSelect(sizeMH, sizebox.top, sizebox.left, (short) sresult);
  2335.                 result = result & 0xffff;
  2336.                 InvertRect(&snambox);
  2337.  
  2338.                 if (result > 0)
  2339.                   {
  2340.                     getitem(sizeMH, (short) result, &sizetemp);
  2341.                     sscanf(sizetemp, "%d", &RScfontsize);
  2342.                     RSdrawsize(dlog, 14);
  2343.                     sresult = result;
  2344.                   } /* if */
  2345.                 break;
  2346. #endif PROMPTFONT
  2347.           } /* switch */
  2348.       } /* while */
  2349.  
  2350.     DisposDialog(dlog);
  2351.  
  2352.   /* force redrawing of entire window contents */
  2353.     SetPort(RSlocal[w].window);
  2354.     InvalRect(&RSlocal[w].window->portRect);
  2355.  
  2356.     if (item == 2)
  2357.         return (-1);
  2358.     else
  2359.         for (x = 0; x < 4; x++)
  2360.             SetEntryColor(RSlocal[w].pal, x, &RSlocal[w].RGBs[x]);
  2361.   /* do something if it changes */;
  2362.  
  2363. #ifdef PROMPTFONT
  2364.     getfnum(&RScfontname, &num);
  2365.     size = RScfontsize;
  2366.     DeleteMenu(fontMH);
  2367.     DeleteMenu(sizeMH);
  2368.  
  2369.     RSchangefont(w, num, size, 1);
  2370. #endif PROMPTFONT
  2371.  
  2372.     return(0);
  2373.   } /* RScprompt */
  2374.  
  2375. int RSsetcolor
  2376.   (
  2377.     int w, /* window number */
  2378.     int n, /* color entry number */
  2379.     unsigned int r, /* components of new color */
  2380.     unsigned int g,
  2381.     unsigned int b
  2382.   )
  2383.   /* sets a new value for the specified color entry of a terminal window. */
  2384.   {
  2385.     if ( !HasColor || (RSsetwind(w) < 0))        /* from Jim@BYU */
  2386.         return(-1);
  2387.     RScurrent->RGBs[n].red = r;
  2388.     RScurrent->RGBs[n].green = g;
  2389.     RScurrent->RGBs[n].blue = b;
  2390.     if (RScolor)
  2391.       {
  2392.       /* only take account of the color settings on a color-capable machine */
  2393.         SetEntryColor(RScurrent->pal, n, &RScurrent->RGBs[n]);
  2394.         SetPort(RScurrent->window);
  2395.         InvalRect(&RScurrent->window->portRect);
  2396.       } /* if */
  2397.     return(0);
  2398.   } /* RSsetcolor */
  2399.  
  2400. void RSgetcolor
  2401.   (
  2402.     int w, /* window number */
  2403.     int n, /* color entry number */
  2404.     unsigned int *r, /* where to return components of color */
  2405.     unsigned int *g,
  2406.     unsigned int *b
  2407.   )
  2408.   /* gets the current value for the specified color entry of a terminal window. */
  2409.   {
  2410.     *r = RSlocal[w].RGBs[n].red;
  2411.     *g = RSlocal[w].RGBs[n].green;
  2412.     *b = RSlocal[w].RGBs[n].blue;
  2413.   } /* RSgetcolor */
  2414.  
  2415. int RSmouseintext                /* Point is in global coords */
  2416.   (
  2417.     int w,
  2418.     long myPoint
  2419.   )
  2420.   /* is myPoint within the text-display area of the specified window. */
  2421.   {
  2422.     return
  2423.         ptinrect((Point *) &myPoint, &RSlocal[w].textrect); 
  2424.   } /* RSmouseintext */
  2425.  
  2426. void RSskip
  2427.   (
  2428.     int w,
  2429.     int on
  2430.   )
  2431.   /* sets the "skip" flag for the specified window (whether ignore
  2432.     screen updates until further notice). */
  2433.   {
  2434.     RSlocal[w].skip = on;
  2435.   } /* RSskip */
  2436.  
  2437. /**********************************************************************************/
  2438. /*  Make sure at least this much memory is available before allocating more memory
  2439. *   for me.  Returns true or false whether that much is available.
  2440. */
  2441. int RSokmem
  2442.   (
  2443.     int amount
  2444.   )
  2445.   {
  2446.     char *p;
  2447.     
  2448.     if (NULL == (p = NewPtr(amount)))
  2449.         return(0);
  2450.     DisposPtr(p);
  2451.     return(1);
  2452.   } /* RSokmem */
  2453.  
  2454. #endif NCSA_TELNET
  2455.